我正在讀取遠程文件中的一些數據,讓每件事情都工作到我寫一些特定行到文本文件時。這裏
問題是,當我喜歡寫東西女孩的金色金屬「X」 CZ環成爲女孩&氏金色金屬&'×&者; CZ環在txt文件中。
我如何寫入txt文件,以便它保留上面寫的文本,而不是顯示字符代碼,但實際字符。
我的代碼示例。寫入特殊字符到txt文件
$content_to_write = '<li class="category-top"><span class="top-span"><a class="category-top" href="'.$linktext.'.html">'.$productName.'</a></span></li>'."\r\n";
fwrite($fp, $content_to_write);
$linktext = "Girls-Goldtone-X-CZ-Ring";
$productName = "Girl's Goldtone 'X' CZ Ring";
的var_dump
string '<li class="category-top"><span class="top-span"><a class="category-top" href="Stellar-Steed-Gallery-wrapped-Canvas-Art.html">'Stellar Steed' Gallery-wrapped Canvas Art</a></span></li>
'(長度= 195)
代碼
$productName =$linktext;
$linktext = str_replace(" ", "-", $linktext);
$delChar = substr($linktext, -1);
if($delChar == '.')
{
$linktext = substr($linktext, 0, -1);
}
$linktext = removeRepeated($linktext);
$linktext = remove_invalid_char($linktext);
$productName = html_entity_decode($productName);
$content_to_write = '<li class="category-top"><span class="top-span"><a class="category-top" href="'.$linktext.'.html">'.$productName.'</a></span></li>'."\r\n";
var_dump($content_to_write);
fwrite($fp, utf8_encode($content_to_write));
這只是一個編碼問題。在外部文件中使用哪種編碼,在查看輸出時使用哪種編碼,以及在寫入.txt文件時使用哪種編碼? – 2012-03-11 10:23:55