str_replace

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
quadoc
Forum Contributor
Posts: 137
Joined: Fri Jul 01, 2005 5:33 pm
Location: Atlanta, GA

str_replace

Post by quadoc »

I tried to use replace the following string from " " to % using the str_replace function, but it doesn't seem to work. When I echo the $newstr it showing "This is" instead of "This%is". Does anyone know why? Please post some tips. Thanks...

Code: Select all

$oldstr = "This is";

$newstr = str_replace(" ","%",$oldstr);
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

are you sure you are trying to replace a space or searching for a space?
User avatar
quadoc
Forum Contributor
Posts: 137
Joined: Fri Jul 01, 2005 5:33 pm
Location: Atlanta, GA

Post by quadoc »

I'm trying to replace the space with the %.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

That doesn't answer the question, sorry.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Are you trying to make your link url friendly? :arrow: urlencode()
litebearer
Forum Contributor
Posts: 194
Joined: Sat Mar 27, 2004 5:54 am

Post by litebearer »

Interesting, just did a quick test and does what you want...

Code: Select all

<?PHP
$test = "This is a car";
$new_test = str_replace (' ', '%', $test);
echo $new_test;
?>

Lite...
Post Reply