note 74938 added to function.ucwords

From: Date: Sat, 05 May 2007 07:49:24 +0000
Subject: note 74938 added to function.ucwords
Groups: php.notes 
Request: Send a blank email to php-notes+get-126210@lists.php.net to get a copy of this message
ucwords() only excepts whitespace in front of a word, although some chars like '"' or '(' normally have no space between them and the following word: <?php $title = 'ELVIS "THE KING" PRESLEY - (LET ME BE YOUR) TEDDY BEAR'; echo ucwords(strtolower($title)); ?> prints: Elvis "the King" Presley - (let Me Be Your) Teddy Bear To avoid this i use a small function adding and deleting blanks behind these chars, and using ucwords() in between: <?php function my_ucwords($string) { $noletters='"([/'; //add more if u need to for($i=0; $i<strlen($noletters); $i++) $string = str_replace($noletters[$i], $noletters[$i].' ', $string); $string=ucwords($string); for($i=0; $i<strlen($noletters); $i++) $string = str_replace($noletters[$i].' ', $noletters[$i], $string); return $string; } $title = 'ELVIS "THE KING" PRESLEY - (LET ME BE YOUR) TEDDY BEAR'; echo my_ucwords(strtolower($title)); ?> prints: Elvis "The King" Presley - (Let Me Be Your) Teddy Bear ---- Server IP: 217.13.201.10 Probable Submitter: 84.158.105.48 ---- Manual Page -- http://www.php.net/manual/en/function.ucwords.php Edit -- https://master.php.net/note/edit/74938 Del: integrated -- https://master.php.net/note/delete/74938/integrated Del: useless -- https://master.php.net/note/delete/74938/useless Del: bad code -- https://master.php.net/note/delete/74938/bad+code Del: spam -- https://master.php.net/note/delete/74938/spam Del: non-english -- https://master.php.net/note/delete/74938/non-english Del: in docs -- https://master.php.net/note/delete/74938/in+docs Del: other reasons-- https://master.php.net/note/delete/74938 Reject -- https://master.php.net/note/reject/74938 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#126210) next »