0

我试图将 php 文件的编码(通过另一个 php 页面)更改为 UTF-8 ,我的意思是没有编辑器。

我尝试使用file_get_contentsfile_put_contents

我使用了这段代码,但它不起作用!

$text = file_get_contents('testencoding.php');
$text = mb_convert_encoding($text, "UTF-8");
file_put_contents('testencoding.php',$text);

仅当页面中有“阿拉伯”字符时,上面的代码才有效。

谢谢,

4

2 回答 2

2

您必须from_encodingmb_convert_encoding函数指定。

如果from_encoding未指定,它将使用内部编码

于 2011-08-23T01:37:57.710 回答
0

尝试:

$text = file_get_contents('testencoding.php');
file_put_contents('testencoding.php',utf8_encode($text));

如果它不起作用,请尝试:

$text = file_get_contents('testencoding.php');
file_put_contents('testencoding.php',utf8_decode($text));

PS:如果可行,请考虑将答案标记为正确,tks :)

于 2011-08-24T08:25:57.500 回答