I am having a really hard time trying to fix a Clients Database records. I need to Find and Replace all Curly Quotes which look like this “
with Straight Quotes "
Attempt 1
I have tried to run this on my MySQL database with no luck.
update wp_posts set post_content = replace(post_content,'“','"');
Attempt 2
I have also tried search and replace in PHP with the below, with no luck as well
<?php
$str = ' “evil curly quotes“ no "good straight quotes"';
str_replace ('“', '"', $str);
echo $str;
// Prints:
// “evil curly quotes“ no "good straight quotes"
?>
Please help me anyone, there has to be an easy way to do this besides manually editing thousands of records?
You are not actually replacing any value. You forgot to assign the return value of the str_replace
call to the $str
variable. This will do the trick:
<?php
$str = ' “evil curly quotes“ no "good straight quotes"';
$str = str_replace ('“', '"', $str);
echo $str;
// Prints:
// “evil curly quotes“ no "good straight quotes"
?>
edit: Tom D also provided the correct answer in his comment (and did it earlier than me to be fair).