syndicate_software
syndicate_software

Reputation: 61

Accent characters are crashing stand alone PHP interpreter

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:

  1. Separate PHP.INI file with: default_charset = utf-8
  2. First line of script: ini_set('default_charset', 'UTF-8');
  3. Made sure that my code editor (ConText) was saving in unicode format.
  4. Google'd everything I could think of for the past hour

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

Answers (1)

syndicate_software
syndicate_software

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

Related Questions