I need to replace for example "This is the 'string'." to "This_is_the_string.". I know how to replace " " with " _ ", but know how to replace " ' " with ""?
Asked
Active
Viewed 329 times
2 Answers
0
This will do it for you:
$s = "This is the 'string'.";
echo str_replace(array(" ", "'"), array("_",''), $s);
str_replace()
can accept multiple arguements via arrays for the $search
and $replace
keys within the $subject
.
mixed str_replace ( mixed $search , mixed $replace , mixed $subject [, int &$count ] )

Darren
- 13,050
- 4
- 41
- 79
0
try passing array in str_replace()
$str = "This is the 'string'.";
echo str_replace(array("'"," "), array('', '_'), $str);
output :- This_is_the_string.

Rakesh Sharma
- 13,680
- 5
- 37
- 44
-
@expresso your welcome :) you need to accept/upvote helpful answers. – Rakesh Sharma Jul 31 '14 at 07:24