1. PHP itself is not encoded, and all strings are generally considered binary streams. So only the string you need to enter is Utf-8. If the string has other encodings, you can use the Iconv series function to convert the encoding.
2, note $content = Iconv ("Utf-8", "Gb2312//ignore", $content); IGNORE Ignore error
<?php
$f
=
fopen
(
"test.txt"
,
"wb"
);
$text
=utf8_encode(
"a!"
); //先用函数utf8_encode将所需写入的数据变成UTF编码格式。
$text
=
"\xEF\xBB\xBF"
.
$text
;
//"\xEF\xBB\xBF",在没有utf8中文情况下,这串字符不可缺少,生成的文件将成为UTF-8格式,否则依然是ANSI格式。
fputs
(
$f
,
$text
);
//写入。
fclose(
$f
);
?>
|
This creates the file encoding format is really utf-8, but placed in the file of Chinese characters appear garbled phenomenon, after some debugging, the code is as follows:
<?php
$ctxtsubmit
=
"好呀"
;
$f
=
fopen
(
"../"
.
$file
,
"wb"
);
//$text=utf8_encode($ctxtsubmit);
//先用函数utf8_encode将所需写入的数据变成UTF编码格式。
$text
=
"\xEF\xBB\xBF"
.
$ctxtsubmit
;
//"\xEF\xBB\xBF",在没有utf8中文情况下,这串字符不可缺少,生成的文件将成为UTF-8格式,否则依然是ANSI格式。
fputs
(
$f
,
$text
);
//写入。
fclose(
$f
);
?>
|
As for "\XEF\XBB\XBF" Why add this string, I do not understand