Makes first letter of each word capital - words must be separated by spaces.
Use with care, this function does not work properly in many locales!!!

@param string $text input string
@return string
770588
public static function strtotitle($text) {
        if (empty($text)) {
            return $text;
        }

        if (function_exists('mb_convert_case')) {
            return mb_convert_case($text, MB_CASE_TITLE, 'UTF-8');
        }

        $text = self::strtolower($text);
        $words = explode(' ', $text);
        foreach ($words as $i=>$word) {
            $length = self::strlen($word);
            if (!$length) {
                continue;

            } else if ($length == 1) {
                $words[$i] = self::strtoupper($word);

            } else {
                $letter = self::substr($word, 0, 1);
                $letter = self::strtoupper($letter);
                $rest   = self::substr($word, 1);
                $words[$i] = $letter.$rest;
            }
        }
        return implode(' ', $words);
    }
275081
protected static function _removeLastWord($text)
    {
        $spacepos = mb_strrpos($text, ' ');

        if ($spacepos !== false) {
            $lastWord = mb_strrpos($text, $spacepos);

            // Some languages are written without word separation.
            // We recognize a string as a word if it doesn't contain any full-width characters.
            if (mb_strwidth($lastWord) === mb_strlen($lastWord)) {
                $text = mb_substr($text, 0, $spacepos);
            }

            return $text;
        }

        return '';
    }
1367489
public static String capitalize( String text )
    {
        if (text == null || text.length() == 0)
            return text;
        
        if (Character.isLowerCase(text.charAt(0)))
            return Character.toUpperCase(text.charAt(0)) + text.substring(1);
        else
            return text;
    }
373580
public function capitalize($string)
    {
        if (!extension_loaded('mbstring')) {
            return ucfirst($string);
        }

        $encoding = Yii::app()->charset;
        $firstChar = mb_strtoupper(mb_substr($string, 0, 1, $encoding), $encoding);
        return $firstChar . mb_substr($string, 1, mb_strlen($string, $encoding) - 1, $encoding);
    }
866405
static function strtolower( $text )
    {
        //We need to detect our internal charset
        if ( self::$charset === null )
        {
            self::$charset = eZTextCodec::internalCharset();
        }

        //First try to use mbstring
        if ( extension_loaded( 'mbstring' ) )
        {
            return mb_strtolower( $text, self::$charset );
        }
        else
        {
            // Fall back if mbstring is not available
            $char = eZCharTransform::instance();
            return $char->transformByGroup( $text, 'lowercase' );
        }
    }
1257042
protected function replaceNamesIn($text)
    {
        $is_string_literal = strpos($text, "'") !== false
            || strpos($text, '"') !== false;
        if ($is_string_literal) {
            return $text;
        }

        $word = '[a-z_][a-z0-9_]+';

        $find = "/(\\b)($word)\\.($word)(\\b)/i";

        $repl = '$1`$2`.`$3`$4';

        $text = preg_replace($find, $repl, $text);

        return $text;
    }
162906
public static function nl2paragraph($text)
    {
        $paragraphs = explode("\n", $text);

        foreach ($paragraphs as &$paragraph) {
            $paragraph = "<p>$paragraph</p>";
        }

        return implode('', $paragraphs);
    }
848528
public function getTitleFromFirstH1($text)
    {
        $matches = [];
        $title = null;

        if (preg_match("#<h1.*?>(.*)</h1>#", $text, $matches)) {
            $title = strip_tags($matches[1]);
        }

        return $title;
    }
826012
public function format($text = '', string $style = 'none')
    {
        return $this->getStartMark($style) . $text . $this->getClearMark();
    }
631357
public static function sentence($string) {
    $pieces = explode(' ', $string);

    // Put the first word into lowercase, unless it's all capitals.
    if (!preg_match('@^[[:upper:]]+$@', $pieces[0])) {
      $pieces[0] = lcfirst($pieces[0]);
    }

    return new StringAssembler($pieces);
  }
555002
public static function toFunctionFormat($text, $separator = '-')
    {
        $camelized = self::toCamelCaseFormat($text, $separator);

        return lcfirst($camelized);
    }
803976
public static function ucWords($string)
    {
        $words = explode(' ', $string);
        $words = array_map('self::ucFirst', $words);

        return implode(' ', $words);
    }
503447
public function split($text)
    {
        $this->probabilityCalculator->setAbbreviations($this->getAbbreviations());

        $tokens = $this->lexer->run($text);
        $probabilities = $this->probabilityCalculator->calculate($tokens);
        $sentences = $this->sentenceBuilder->build($probabilities);

        return $sentences;
    }
1214425
public function stem($text)
    {
        $normalizedText = Filter\TextNormalizer::normalizeText($text);

        $words = explode(' ', $normalizedText);
        $stems = array();

        foreach ($words as $word) {
            $stems[] = $this->stemWord($word);
        }

        return implode(' ', $stems);
    }
1060975
public static function toCamelCaseFormat($text, $separator = '-')
    {
        $slugified = self::urlize($text, $separator);
        $camel = strtolower($slugified);
        $camel = ucwords($camel, $separator);

        return str_replace($separator, '', $camel);
    }
1212398
public function apply($text) {
		$lines = preg_split("/\\r\\n|\\n|\\r/", $text);

		$lines = $this->wrapLines($lines, $this->padding);

		$lines = array_map(function ($line) {
			return parent::apply($line);
		}, $lines);

		$lines = $this->wrapLines($lines, $this->margin);

		return implode(PHP_EOL, $lines);;
	}
394070
public static function convertToCamelCase($text, $ucfirst = true)
    {
        $text = preg_replace_callback('#[_-]([a-z])#i', function ($matches) {
            return strtoupper($matches[1]);
        }, strtolower($text));

        return $ucfirst ? ucfirst($text) : $text;
    }