PHP's method for generating UTF8 files

  • 2020-03-31 20:46:27
  • OfStack


<?php 
$f=fopen("test.txt", "wb"); 
$text=utf8_encode("a!"); 
//Use the function utf8_encode to convert the data you want to write into a UTF encoding format.
$text="\xEF\xBB\xBF".$text; 
//"\xEF\xBB xBF", this string of characters is indispensable, the generated file will be in utf-8 format, otherwise it will still be in ANSI format.
fputs($f, $text); 
//Write.
fclose($f); 
?> 

Related articles: