homer.favenir Posted July 28, 2008 Share Posted July 28, 2008 hi, can anyone please tell me how to do this. my script is: <?php $x = 'ABARQUEZ-AGCAOILI, CARMENCITA DR STATE U *OF N*Y SYRACUSE \'79'; echo ucwords(strtolower($x)); ?> the output Abarquez-agcaoili, Carmencita Dr State U *of N*y Syracuse '79 but the expected output should be Abarquez-Agcaoili, Carmencita Dr State U of NY Syracuse '79 please..... Link to comment https://forums.phpfreaks.com/topic/116932-solved-uppercase-to-normal-case/ Share on other sites More sharing options...
ratcateme Posted July 28, 2008 Share Posted July 28, 2008 i am not sure where you got the idea that adding a * in front of a character would change anything but php.net says words are capitalized if they are preceded by "space, form-feed, newline, carriage return, horizontal tab, and vertical tab". also a - does not work because it is not in the previous list. if you really need this you could create a user defined function. Scott. Link to comment https://forums.phpfreaks.com/topic/116932-solved-uppercase-to-normal-case/#findComment-601316 Share on other sites More sharing options...
homer.favenir Posted July 28, 2008 Author Share Posted July 28, 2008 * is already given in the string. that is the real format. i have to make the *, - into white space and use the ucword? Link to comment https://forums.phpfreaks.com/topic/116932-solved-uppercase-to-normal-case/#findComment-601318 Share on other sites More sharing options...
corbin Posted July 28, 2008 Share Posted July 28, 2008 Not the best speed wise of look wise ever, but this will work: <?php $x = 'ABARQUEZ-AGCAOILI, CARMENCITA DR STATE U *OF N*Y SYRACUSE \'79'; function strtoupper_ghetto($p1, $p2) { $p2 = strtoupper($p2); return ($p1 == '*') ? $p2 : $p1 . $p2; } echo preg_replace('/([-|*])([a-z]{1})/e', "strtoupper_ghetto('$1', '$2')", ucwords(strtolower($x))); Link to comment https://forums.phpfreaks.com/topic/116932-solved-uppercase-to-normal-case/#findComment-601325 Share on other sites More sharing options...
homer.favenir Posted July 28, 2008 Author Share Posted July 28, 2008 nice script! can you kindly pls explain the expression... thanks a lot budz! Link to comment https://forums.phpfreaks.com/topic/116932-solved-uppercase-to-normal-case/#findComment-601328 Share on other sites More sharing options...
homer.favenir Posted July 28, 2008 Author Share Posted July 28, 2008 Not the best speed wise of look wise ever, but this will work: <?php $x = 'ABARQUEZ-AGCAOILI, CARMENCITA DR STATE U *OF N*Y SYRACUSE \'79'; function strtoupper_ghetto($p1, $p2) { $p2 = strtoupper($p2); return ($p1 == '*') ? $p2 : $p1 . $p2; } echo preg_replace('/([-|*])([a-z]{1})/e', "strtoupper_ghetto('$1', '$2')", ucwords(strtolower($x))); where does the $1 and $2 came from? Link to comment https://forums.phpfreaks.com/topic/116932-solved-uppercase-to-normal-case/#findComment-601342 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.