Skip to content Skip to sidebar Skip to footer

Php: How To Write File To Disk With Unicode Characters

I need to write out a file to disk with special ISO-8859-15 characters. For my own testing purposes, I used: —©®±àáâãäåæÒÓÔÕÖ¼½¾§µçðþú–.jpg ...but the

Solution 1:

I've found my own answer. First, I need WINDOWS-1252 encoding, as it turns out. Second, all I need to do is use inconv(), converting from 'UTF-8' to 'WINDOWS-1252', like so:

<?php// First, create a text file with the em-dash and the copyright symbol, then put the file prefix into the file:$filename1 = "000—©—©.txt";
    $content1 = "000—©—©";

    // Judicious use of iconv() does the trick:$filename1 = iconv('UTF-8', 'WINDOWS-1252', $filename1);
    file_put_contents($filename1, $content1);
?>

My only lingering question, provided that I'm testing this on XAMPP on my local Windows machine, is whether WINDOWS-1252 encoding will work on actual servers at the major hosting services (GoDaddy, etc.) If not, is there a different encoding that supports everything included in WINDOWS-1252 but better suited for non-XAMPP localhost servers?

There's a complete listing of encodings supported by iconv here. Several are on the same line as WINDOWS-1252; does that mean they are interchangeable?

Many thanks, Tom

Post a Comment for "Php: How To Write File To Disk With Unicode Characters"