note 118926 added to function.ucwords

From: Date: Mon, 29 Feb 2016 20:36:47 +0000
Subject: note 118926 added to function.ucwords
Groups: php.notes 
Request: Send a blank email to php-notes+get-205069@lists.php.net to get a copy of this message
ucwords for human names in Brazil. ucwords personalizada para nomes próprios brasileiros. <?php /** * ucwords for human names in Brazil * Edit from http://php.net/manual/pt_BR/function.ucwords.php#112795 * @param string $str * @param array $delimiters * @param array $exceptions Exceptions are words you don't want converted * @return string */ function name($str, $delimiters = array( " ", "-", ".", "'", "O'", "Mc", ), $exceptions = array( "de", "do", "da", "dos", "das", )) { $result = ''; foreach ($delimiters as $delimiter) { # If string has a delimiter if (strstr($str, $delimiter)) { $ucfirst = array(); # Apply ucfirst to every word foreach (explode($delimiter, mb_strtolower($str)) as $word) { $word = mb_convert_case($word, MB_CASE_TITLE); # Working with exceptions if (in_array(mb_strtoupper($word), $exceptions)) { $word = mb_strtoupper($word); } elseif (in_array(mb_strtolower($word), $exceptions)) { $word = mb_strtolower($word); } elseif (preg_match('/^M{0,4}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})$/', mb_strtoupper($word))) { # Is roman numerals? # http://stackoverflow.com/a/267405/437459 $word = mb_strtoupper($word); } $ucfirst[] = $word; } # string's first character uppercased $result = implode($delimiter, $ucfirst); } } return $result; } ?> ---- Server IP: 72.52.91.14 Probable Submitter: 200.129.37.8 ---- Manual Page -- http://php.net/manual/en/function.ucwords.php Edit -- https://master.php.net/note/edit/118926 Del: integrated -- https://master.php.net/note/delete/118926/integrated Del: useless -- https://master.php.net/note/delete/118926/useless Del: bad code -- https://master.php.net/note/delete/118926/bad+code Del: spam -- https://master.php.net/note/delete/118926/spam Del: non-english -- https://master.php.net/note/delete/118926/non-english Del: in docs -- https://master.php.net/note/delete/118926/in+docs Del: other reasons-- https://master.php.net/note/delete/118926 Reject -- https://master.php.net/note/reject/118926 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#205069) next »