note 76786 added to function.ucwords

From: Date: Mon, 30 Jul 2007 20:02:39 +0000
Subject: note 76786 added to function.ucwords
Groups: php.notes 
Request: Send a blank email to php-notes+get-129057@lists.php.net to get a copy of this message
Here is a function to capitalize a last name, accounting for hyphens, apostrophes, "Mc" and "Mac": <?php function CapitalizeLastName($name) { $name = strtolower($name); $name = join("'", array_map('ucwords', explode("'", $name))); $name = join("-", array_map('ucwords', explode("-", $name))); $name = join("Mac", array_map('ucwords', explode("Mac", $name))); $name = join("Mc", array_map('ucwords', explode("Mc", $name))); return $name; } ?> I speed tested it against functions that used preg_replace() with an "e" modifier, preg_replace_callback(), and a character-by-character parsing. Unexpectedly, this function using join(), array_map() and explode() was fastest. ---- Server IP: 64.71.164.2 Probable Submitter: 216.194.126.99 ---- Manual Page -- http://www.php.net/manual/en/function.ucwords.php Edit -- https://master.php.net/note/edit/76786 Del: integrated -- https://master.php.net/note/delete/76786/integrated Del: useless -- https://master.php.net/note/delete/76786/useless Del: bad code -- https://master.php.net/note/delete/76786/bad+code Del: spam -- https://master.php.net/note/delete/76786/spam Del: non-english -- https://master.php.net/note/delete/76786/non-english Del: in docs -- https://master.php.net/note/delete/76786/in+docs Del: other reasons-- https://master.php.net/note/delete/76786 Reject -- https://master.php.net/note/reject/76786 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#129057) next »