예제 #1
0
 /**
  * Returns a trimmed string with the first letter of each word capitalized.
  * Ignores the case of other letters, preserving any acronyms. Also accepts
  * an array, $ignore, allowing you to list words not to be capitalized.
  *
  * @param  array   $ignore An array of words not to capitalize
  * @return Stringy Object with a titleized $str
  */
 public function titleize($ignore = null)
 {
     $buffer = $this->trim();
     $encoding = $this->encoding;
     $buffer = preg_replace_callback('/([\\S]+)/u', function ($match) use($encoding, $ignore) {
         if ($ignore && in_array($match[0], $ignore)) {
             return $match[0];
         } else {
             $stringy = new Stringy($match[0], $encoding);
             return (string) $stringy->upperCaseFirst();
         }
     }, $buffer);
     return new Stringy($buffer, $encoding);
 }