ukweb Posted September 3, 2007 Share Posted September 3, 2007 Hi, I would like all '_' in a string to be replaced with a space, how do I do this? Basically the variable is $row_featured['address2'] and there are values such as 'rhos_on_sea' assigned to it, and when I echo it I want to echo it as 'rhos on sea' instead... I'm guessing I use str_replace but I've played around and had no luck... Thanks! Ste Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted September 3, 2007 Share Posted September 3, 2007 use str_replace Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted September 3, 2007 Share Posted September 3, 2007 <?php str_replace('_',' ', $row_featured); echo ( $row_featured); ?> Quote Link to comment Share on other sites More sharing options...
Jessica Posted September 3, 2007 Share Posted September 3, 2007 If you lookup the function in the manual you'll see why that won't work. The function returns the new string, your code will not accomplish anything. Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted September 3, 2007 Share Posted September 3, 2007 <?php $row_featured= $_GET[address2]; $row_featured=str_replace('_',' ', $row_featured); echo ( $row_featured); ?> Quote Link to comment Share on other sites More sharing options...
ukweb Posted September 4, 2007 Author Share Posted September 4, 2007 $town = $row_featured['address3']; $town = str_replace('_',' ', $town); echo $town; Works fine... BUT I use $town in a repeat region in dreamweaver, and therefore the town stays the same for all records. How can I do this to work with the repeat region??!?!?! HELP!!!! Thanks Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted September 4, 2007 Share Posted September 4, 2007 <?php $town = array($row_featured['address3'],$row_featured['adress2'],$row_featured['adress1']); $town = str_replace('_',' ', $town); echo $town;?> note: echoing town will echo all row fields listed.IE if you have adress fields 1-3 it will echo adress fields 1-3. Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted September 4, 2007 Share Posted September 4, 2007 lets just say we want to array one town instead of all towns then we would do <?php $town = array($row_featured['address3'],$row_featured['adress2'],$row_featured['adress1']); $town = str_replace('_',' ', $town); echo {"You are from:"($row_featured['address3']);} else echo {"You are from:"($row_featured['address2']);} else echo {"You are from:"($row_featured['address1']);} ?> Quote Link to comment Share on other sites More sharing options...
ukweb Posted October 10, 2007 Author Share Posted October 10, 2007 works now thanks for the help! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.