note 102033 added to function.ucwords
| From: | e-mike at osu1 dot php dot net | Date: | Mon, 24 Jan 2011 15:49:31 +0000 |
| Subject: | note 102033 added to function.ucwords | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-176247@lists.php.net to get a copy of this message | ||
I used "dyler85" code and tuned it some more, also encoding ready.
<?php
if ( ! function_exists('mb_ucwords'))
{
/**
* Uppercase the first character of each word in a string
*
* $str = "côte d'ivoire mcdonalds hobby's 's avonds s'il vous plaît
jean-luke picard füÃe foo'bar o'foo (bar) [bar] {bar}";
* $str = mb_strtolower($str, 'UTF-8');
* echo mb_ucwords($str, 'UTF-8');
* "Côte d'Ivoire McDonalds Hobby's 's Avonds S'il Vous Plaît
S'ill Jean-Luke Picard FüÃe Foo'bar O'Foo (Bar) [Bar] {Bar}"
*
* @param string $str required
* @param string $encoding optional, default mb_internal_encoding
* @return string
*/
function mb_ucwords($str, $encoding = '')
{
empty($encoding) and $encoding = mb_internal_encoding();
$str = mb_convert_case($str, MB_CASE_TITLE, $encoding);
$str = preg_replace(
'/(?: ^ | \\b )(( [D]\' )|( \w{1}\' | Ma?c | Fitz ))([^\W\d_])([^il])/xe',
"mb_strtolower('\$2',
'UTF-8').'\$3'.mb_strtoupper('\$4',
'UTF-8').'\$5'", $str);
return $str;
}
}
?>
----
Server IP: 69.147.83.197
Probable Submitter: 62.195.81.232
----
Manual Page -- http://www.php.net/manual/en/function.ucwords.php
Edit -- https://master.php.net/note/edit/102033
Del: integrated -- https://master.php.net/note/delete/102033/integrated
Del: useless -- https://master.php.net/note/delete/102033/useless
Del: bad code -- https://master.php.net/note/delete/102033/bad+code
Del: spam -- https://master.php.net/note/delete/102033/spam
Del: non-english -- https://master.php.net/note/delete/102033/non-english
Del: in docs -- https://master.php.net/note/delete/102033/in+docs
Del: other reasons-- https://master.php.net/note/delete/102033
Reject -- https://master.php.net/note/reject/102033
Search -- https://master.php.net/manage/user-notes.php