note 107701 modified in function.ucwords by danbrown
| From: | danbrown@php.net | 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; <?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 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 ?>
--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