note 107701 modified in function.ucwords by danbrown

From: Date: Thu, 10 May 2012 20:18:15 +0000
Subject: note 107701 modified in function.ucwords by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-187783@lists.php.net to get a copy of this message
A proper Turkish solution;&#13;&#10;&#13;&#10;&#60;?php&#13;&#10;function ucfirst_turkish($str) {&#13;&#10;&#9;$tmp = preg_split(&#34;//u&#34;, $str, 2, PREG_SPLIT_NO_EMPTY);&#13;&#10;&#9;return mb_convert_case(&#13;&#10;&#9;&#9;str_replace(&#34;i&#34;, &#34;İ&#34;, $tmp[0]), MB_CASE_TITLE, &#34;UTF-8&#34;).&#13;&#10;&#9;&#9;$tmp[1];&#13;&#10;}&#13;&#10;&#13;&#10;function ucwords_turkish($str) {&#13;&#10;&#9;return preg_replace(&#34;/(\\w+)/ue&#34;, &#34;ucfirst_turkish(&#39;\\\\1&#39;).&#39;$2&#39;&#34;, $str);&#13;&#10;}&#13;&#10;&#13;&#10;$str = &#34;iyilik güzelLİK şeker &#34;;&#13;&#10;echo ucwords($str) .&#34;\\n&#34;; // Iyilik GüzelLİK şeker &#13;&#10;echo ucwords_turkish($str); // İyilik GüzelLİK Şeker &#13;&#10;?&#62; --was-- A proper Turkish solution; <?php function ucfirst_turkish($str) { $tmp = preg_split("//u", $str, 2, PREG_SPLIT_NO_EMPTY); return mb_convert_case( str_replace("i", "İ", $tmp[0]), MB_CASE_TITLE, "UTF-8"). $tmp[1]; } // function ucwords_turkish($str) { // return join(" ", array_map( // "ucfirst_turkish", preg_split("/\s/u", $str))); // } function ucwords_turkish($str) { return preg_replace("/(\w+)/ue", "ucfirst_turkish('\\1').'$2'", $str); } $str = "iyilik güzelLİK şeker "; echo ucwords($str) ."\n"; // Iyilik GüzelLİK şeker echo ucwords_turkish($str); // İyilik GüzelLİK Şeker ?> http://php.net/manual/en/function.ucwords.php

« previous php.notes (#187783) next »