Jump to content

[SOLVED] uppercase to normal case


homer.favenir

Recommended Posts

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

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.

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)));

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.