note 114291 added to function.mb-ereg-replace
| From: | marco at thenetworksolution dot it | Date: | Mon, 03 Feb 2014 14:47:40 +0000 |
| Subject: | note 114291 added to function.mb-ereg-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-198398@lists.php.net to get a copy of this message | ||
To selectively uppercase parts of a string via mb_eregi_replace
$str = mb_eregi_replace('\b([0-9]{1,4}[a-z]{1,2})\b', "strtoupper
('\\1')", $str, 'e');
Full example, how to fix an address manually typed, uppercasing the first letter of a words and
keeping uppercase roman numerals and the letters A,B,C after the house number):
function ucAddress($str) {
// first lowercase all and use the default ucwords
$str = ucwords(strtolower($str));
// let's fix the default ucwords...
// uppercase letters after house number (was lowercased by the strtolower above)
$str = mb_eregi_replace('\b([0-9]{1,4}[a-z]{1,2})\b', "strtoupper
('\\1')", $str, 'e');
// the same for roman numerals
$str = mb_eregi_replace('\bM{0,4}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})\b',
"strtoupper('\\0')", $str, 'e');
return $str;
}
----
Server IP: 46.252.156.25
Probable Submitter: 93.56.145.149
----
Manual Page -- http://php.net/manual/en/function.mb-ereg-replace.php
Edit -- https://master.php.net/note/edit/114291
Del: integrated -- https://master.php.net/note/delete/114291/integrated
Del: useless -- https://master.php.net/note/delete/114291/useless
Del: bad code -- https://master.php.net/note/delete/114291/bad+code
Del: spam -- https://master.php.net/note/delete/114291/spam
Del: non-english -- https://master.php.net/note/delete/114291/non-english
Del: in docs -- https://master.php.net/note/delete/114291/in+docs
Del: other reasons-- https://master.php.net/note/delete/114291
Reject -- https://master.php.net/note/reject/114291
Search -- https://master.php.net/manage/user-notes.php