Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/67829-replace-character/
Share on other sites

$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

Link to comment
https://forums.phpfreaks.com/topic/67829-replace-character/#findComment-341215
Share on other sites

<?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.

Link to comment
https://forums.phpfreaks.com/topic/67829-replace-character/#findComment-341408
Share on other sites

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']);}





?>

Link to comment
https://forums.phpfreaks.com/topic/67829-replace-character/#findComment-341427
Share on other sites

  • 1 month later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.