I am attempting to use the solution found in this link to remove Microsoft smart quotes from a string before I export the data to CSV file. However, it doesn't seem to be working for me.
This is my code:
$Wp_NewsText = str_replace(
array(chr(145), chr(146), chr(147), chr(148), chr(151)),
array("'", "'", "\"", "\"", "-"),
$Wp_NewsText
);
But for some reason the download still contains the smart quotes. I thought it might be that, because a CSV needs double quotes as a delimiter, it was somehow reverting the quotes back to smart quotes, so I tried this:
$Wp_NewsText = str_replace(
array(chr(145), chr(146), chr(147), chr(148), chr(151)),
array("'", "'", """, """, "‐"),
$Wp_NewsText
);
But that didn't solve the problem. So I tried copy-pasting the actual characters in to the array:
$Wp_NewsText = str_replace(
array(chr(145), chr(146), chr(147), chr(148), chr(151), "“", "”"),
array("'", "'", """, """, "‐", """, """),
$Wp_NewsText
);
But alas, still no luck. Finally I've tried JSON encoding/decoding everything because apparently that's faster, but I was hoping it might have some other useful side-effect of making the code work.
$Wp_NewsText = json_decode(
str_replace(
array(chr(145), chr(146), chr(147), chr(148), chr(151), "“", "”"),
array("'", "'", """, """, "‐", """, """),
json_encode($Wp_NewsText)
)
);
Nope.
The actual string I'm attempting to replace these characters in is as follows:
“There is significant intellectual property to be gleaned from these advanced automotive technology development programs; not least being the pursuit of silent drivetrains, where we’re focusing significant effort,” Setter said.
EDIT: If it matters, all of my code and text is UTF-8 encoded.