开发者

How can i change the encoding of a php page?

开发者 https://www.devze.com 2023-03-29 19:05 出处:网络
Im trying to change the encoding of a php file (through another php page) to UTF-8 , i mean without editor .

Im trying to change the encoding of a php file (through another php page) to UTF-8 , i mean without editor .

i tried to use file_get_contents an开发者_高级运维d file_put_contents .

i used this code but it doesn't work !

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

this code above is working only if there is a "arabic" characters in the page.

Thanks,


You must specify from_encoding for the mb_convert_encoding function.

If from_encoding is not specified, it'll use the internal encoding.


Try:

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

if it doesn't work, try:

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

PS: consider marking the answer as correct if it works, tks :)

0

精彩评论

暂无评论...
验证码 换一张
取 消