【发布时间】:2012-03-11 10:20:26
【问题描述】:
我正在从远程文件中读取一些数据,直到我将一些特定行写入文本文件时,一切都正常工作。
这里的问题是,当我写类似 Girl's Goldtone 'X' CZ Ring 之类的东西时,它会变成 Girl & apos;s Goldtone &apos ;X & apos; txt 文件中的 CZ 环。
我如何写入 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文件时使用哪种编码?
标签: php