Page 1 of 1
str_replace
Posted: Fri Jul 07, 2006 1:49 pm
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);
Posted: Fri Jul 07, 2006 1:55 pm
by feyd
are you sure you are trying to replace a space or searching for a space?
Posted: Fri Jul 07, 2006 2:54 pm
by quadoc
I'm trying to replace the space with the %.
Posted: Fri Jul 07, 2006 3:34 pm
by feyd
That doesn't answer the question, sorry.
Posted: Fri Jul 07, 2006 3:37 pm
by John Cartwright
Are you trying to make your link url friendly?
urlencode()
Posted: Fri Jul 07, 2006 3:44 pm
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...