views:

77

answers:

2

I want to replace single quote (') in a string.

Apparently this will not work...:

$patterns = array();
$replacements = array();
$patterns[0] = "'";
$patterns[1] = '\'';
$replacements[0] = 'Something';
$replacements[2] = 'Same thing just in a other way';
+1  A: 

Replacing (') with (") works fine for me with str_ireplace.

$test = str_ireplace("'", "\"", "I said 'Would you answer me?'");
echo $test; // I said "Would you answer me?" 

Also works fine replacing (") with (')

$test = str_ireplace("\"", "'", "I said \"Would you answer me?\"");
echo $test; // I said 'Would you answer me?' 
Anthony Forloney
A: 
status203