note 114292 added to function.mb-ereg-replace

From: Date: Mon, 03 Feb 2014 14:47:56 +0000
Subject: note 114292 added to function.mb-ereg-replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-198399@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; } Dr. Marco Marsala Network Solution srl http://www.realizzazionesitigenova.it ---- 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/114292 Del: integrated -- https://master.php.net/note/delete/114292/integrated Del: useless -- https://master.php.net/note/delete/114292/useless Del: bad code -- https://master.php.net/note/delete/114292/bad+code Del: spam -- https://master.php.net/note/delete/114292/spam Del: non-english -- https://master.php.net/note/delete/114292/non-english Del: in docs -- https://master.php.net/note/delete/114292/in+docs Del: other reasons-- https://master.php.net/note/delete/114292 Reject -- https://master.php.net/note/reject/114292 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#198399) next »