Codice PHP:
<?php
$text 
"Hello World!";
$f=fopen("test.txt""wb"); // 'b' flag per forzare il formato binary
$text=utf8_encode($text); 
fputs($f$text); 
fclose($f); 
?>
Se vuoi aggiungere il BOM (Byte order mark)

Codice PHP:
<?php
define
("BOM""\\xEF\\xBB\\xBF");

$text "Hello World!";
$f=fopen("test.txt""wb"); 
$text=utf8_encode($text); 
// aggiunge il BOM in testa al file 
$text=BOM.$text
fputs($f$text); 
fclose($f); 
?>