-3

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

expresso
  • 25
  • 1
  • 4

2 Answers2

0

This will do it for you:

$s = "This is the 'string'.";
echo str_replace(array(" ", "'"), array("_",''), $s);

Example


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