Running in PHP 5, I have tried the following two commands to upload from a ISO-8859-1 string to a UTF-8 database that links to UTF-8 web pages:
$data[] = utf8_encode((string)$child);
... or:
$data[] = convertToUtf8((string)$child);
function convertToUtf8($text) {
// cURL('http://'.$url);
preg_match('/<meta.*?charset=(|\")(.*?)("|\")/i', $html, $matches);
$charset = $matches[2];
if($charset)
return mb_convert_encoding($text, 'UTF-8', $charset);
else
return $text;
}
If I execute the PHP script directly by accessing the file from the browser, either one of these works like a charm : the « é » imported is its nice French self. HOWEVER, when I try to execute the same script from a Unix terminal SSH (cron job OR command line), it does not convert the code and so the « é » shows up as « é ».
Any ideas?? I've tried deleting the cron job and replacing the script to make sure the code was going through. This is getting maddening!
Update - the solution
It turns out this particular functionality needs a later version of PHP. Executing it in the Terminal with the following command (and writing the command as such in the cron job) takes care of the problem:
php5.4 xmluploader.php