2011-08-23 94 views
0

進出口試圖(通過另一個PHP頁面)更改php文件的編碼設置爲UTF-8,我的意思是沒有編輯器。我怎樣才能改變一個PHP頁面的編碼?

我試圖用的file_get_contentsfile_put_contents

我用這個代碼,但它不工作!

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

上述代碼僅在頁面中存在「阿拉伯語」字符時纔有效。

感謝,

+1

而在其他案件 - 它做了什麼?定義'不起作用'。如果你知道它,爲什麼不指定'from_encoding'? – zerkms

+0

Im對不起英文不好,我不知道'from_encoding',因爲即時通訊製作網站將編碼從任何編碼轉換爲UTF-8,我嘗試使用'mb_detect_encoding',但它返回'布爾(false)'。 。 謝謝。 – Programmer4me

回答

2

必須爲mb_convert_encoding功能指定from_encoding

如果from_encoding沒有指定,it'll use the internal encoding

+0

什麼是默認'from_encoding'?它是ansi嗎?或者是什麼 ? – Programmer4me

+0

默認'from_encoding'是內部編碼。 – sanmai

+0

@ Programmer4me - 你可以通過查看'mb_internal_encoding()'來獲得內部編碼。 – borrible

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 :)