Welcome to WebmasterWorld Guest from 34.239.158.107

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

replacing underscores with a Space in output

how to do this?

     
2:06 pm on Sep 27, 2004 (gmt 0)

Full Member

10+ Year Member

joined:Feb 21, 2002
posts:228
votes: 0


I have the following that capitalizes the Text Output for US state names:

<?php
$str = $state;
$str = strtoupper($str);
echo $str; // Prints State in CAPITALS
?>

How do I add a "replace" to this to also replace the underscores in the states such as south_dakota, north_dakota, etc?

Thanks

2:09 pm on Sept 27, 2004 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lorax is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Mar 31, 2002
posts:7577
votes: 4


What you need is str_replace [us2.php.net].
2:17 pm on Sept 27, 2004 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 22, 2002
posts:2546
votes: 0


Hello,

pretty simple actually, you use str_replace() [php.net]

$str = str_replace('_', ' ', strtoupper($str));

Birdman

quick, Lorax! :)

2:40 pm on Sept 27, 2004 (gmt 0)

Full Member

10+ Year Member

joined:Feb 21, 2002
posts:228
votes: 0


Thanks Lorax and Birdman - worked like a charm of course. I'm trying to get better at this. PHP isn't my particular forte - but my programmers are extremely busy and I'm trying to "help" on smaller projects - lol. Once I saw it I understood it, so at least that is a step forward. Thanks again.
3:41 pm on Sept 27, 2004 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lorax is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Mar 31, 2002
posts:7577
votes: 4


>> and I'm trying to "help"

I charge my clients twice as much when they try to help. ;)