I tried to create a utf-8 file with this script: $f = fopen($_POST["id"].".inc", "wb"); $text = "\xEF\xBB\xBF".$_POST["text"]; fwrite($f, utf8_encode($text)); fclose($f); Code (markup): but all I get is this: ×’×’×›×’×›×’×’×›×›×’×’×›×›×’ Code (markup): thanks in advance.
it has no errors I go to that page after a form. here's the whole script: <?php if(isset($_POST["id"])){ $f = fopen($_POST["id"].".inc", "wb"); $text = "\xEF\xBB\xBF".$_POST["text"]; fwrite($f, utf8_encode($text)); fclose($f); } else { ?> <form action="create.php" method="POST"> <textarea rows="15" cols="50" name="text" id="text"></textarea><br> <input type="text" name="id" value=""><br> <input type="submit" value="create file"> </form> <?php } ?> Code (markup):
may be: $f = fopen($_POST["id"].".inc", "wb"); $text = $_POST["text"]; fwrite($f, "\xEF\xBB\xBF".utf8_encode($text)); fclose($f); PHP:
Do you know that utf8_encode() encodes an ISO-8859-1 string to UTF-8? It seems that you use not an ISO-8859-1 encoding.
ow thanks. and here is the code who solved my problem: <?php function writeUTF8File($filename,$content) { $f=fopen($filename,"w"); # Now UTF-8 - Add byte order mark fwrite($f, pack("CCC",0xef,0xbb,0xbf)); fwrite($f,$content); fclose($f); } ?> PHP:
Just remove first 3 bytes from string. Implementation depends on your files size. $a=file($fname); $a=implode($a); $a=substr($a,3); PHP: