4

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?

ThinkingStiff
  • 64,767
  • 30
  • 146
  • 239
  • Is your PHP file stored as UTF-8 or as ANSI? You can check it (and change it) in Notepad++ amongst others. If you use UTF-8, make sure you use multibyte-safe functions (mb_*). – GolezTrol Aug 30 '12 at 22:48
  • If nothing is being output to the CSV file then you should get some errors or at least an exception. Would help to see some code. – Flukey Aug 30 '12 at 22:49
  • did u try some encoding techniques ? like `PHP's` `urlencode()` ?? Does that help. I am not sure!! Can u post few codes ?? – Deepak Aug 30 '12 at 22:51
  • @deepak - why would he use urlencode? nothing to do with his problem. – Flukey Aug 30 '12 at 22:51
  • @Flukey If the code is crashing because of some special characters he is using!! I am not sure without looking at the codes.. It was just a suggestion.. – Deepak Aug 30 '12 at 22:53
  • Showing us a piece of code may help.. – GolezTrol Aug 30 '12 at 23:13
  • Thanks to All for the help, but I figured it out. (I feel like an idiot for not finding this earlier) I wasn't using 'utf8_encode()' anywhere. – syndicate_software Aug 31 '12 at 23:41

1 Answers1

2

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?";
Mikulas Dite
  • 7,790
  • 9
  • 59
  • 99