Reputation: 61
I have a PHP script that is run via command line & stand-alone PHP interpreter. The script outputs a lot of html into a CSV file, which is later bulk-uploaded to a WP site.
Accent characters seem to crash the interpreter. ex:
$output = "Não encontrou o que você está procurando?";
$english = "Did not find what you're looking for?";
Whenever I try to manipulate the $output
string, nothing is output to the CSV file, but if I use the $english translation instead, everything works perfectly.
I'm sure that it has something to do with the interpreter not using UTF-8 encoding, but I can't figure out how to fix it.
I've tried:
default_charset = utf-8
ini_set('default_charset', 'UTF-8');
I know that I could break down the string into it's html entities (ã = & atilde;), but I'd REALLY rather not do that, because there will be many of these strings, and some of them will be changing every so often.
Is there any other solution to getting the PHP interpreter to parse the accent characters without blowing up?
Upvotes: 4
Views: 454
Reputation: 61
I wasn't using utf8_encode()
anywhere. Once I added that, everything worked great.
$output = "Não encontrou o que você está procurando?";
$output = utf8_encode($output); // THIS FIXED IT
$english = "Did not find what you're looking for?";
Upvotes: 2