简体   繁体   English

显示某些字符时出现问题

[英]Problems displaying some characters

I've got an XML file from which I've extracted the following text - 我有一个XML文件,从中提取了以下文本-

The Sansa Clip+ MP3 player gives you more to enjoy. Sansa Clip + MP3播放器为您带来更多享受。 Enjoy up to 2,000 songs†† with an 8GB* player, FM radio, long-life battery and voice recorder. 配备8GB *播放器,FM收音机,长寿命电池和录音机,最多可欣赏2,000首歌曲††。 PLUS now even more! 现在加更多! Expand your enjoyment when you add in preloaded content cards** into the new memory card slot, including slotRadio™ and slotMusic™ cards**. 将预装的内容卡**添加到新的存储卡插槽(包括slotRadio™和slotMusic™卡**)中时,可以尽情享受。 Or, save your own music, podcasts, and audio books onto a microSD™/microSDHC™ memory card** to expand your play.It's brought to you by SanDisk with awesome sound to enjoy your music. 或者,将您自己的音乐,播客和有声读物保存到microSD™/ microSDHC™存储卡上**,以扩展您的播放。SanDisk带来了震撼的声音,让您欣赏音乐。 Just clip it on and enjoy more music with an incredible 15 hours† battery-fueled fun. 只需剪辑一下,即可享受令人难以置信的15小时电池供电乐趣,享受更多音乐。 See what you're listening to with the bright, easy-to-read screen and intuitively searchable menus. 明亮,易于阅读的屏幕和直观可搜索的菜单可让您看到正在聆听的内容。 Color your world in red, blue or sleek black undertones. 用红色,蓝色或光滑的黑色底色为您的世界增色。

Why does it display on my webpage as below and how can I fix it automatically? 为什么它显示在我的网页上,如下所示,如何自动修复? Thanks. 谢谢。

The Sansa Clip+ MP3 player gives you more to enjoy. Enjoy up to 2,000 songs††with an 8GB* player, FM radio, long-life battery and voice recorder. Sansa Clip + MP3播放器带给您更多享受。使用8GB *播放器,FM收音机,长寿命电池和录音机,欣赏多达2,000首歌曲。 PLUS now even more! 现在加更多! Expand your enjoyment when you add in preloaded content cards** into the new memory card slot, including slotRadioâ„¢ and slotMusicâ„¢ cards**. 将预装的内容卡**添加到新的存储卡插槽(包括slotRadio™和slotMusic™卡**)中时,可以尽情享受。 Or, save your own music, podcasts, and audio books onto a microSDâ„¢/microSDHCâ„¢ memory card** to expand your play.It’s brought to you by SanDisk with awesome sound to enjoy your music. 或者,将您自己的音乐,播客和有声读物保存到microSD™/ microSDHC™存储卡上**,以扩展您的播放。SanDisk带来的声音令人赞叹,可以欣赏音乐。 Just clip it on and enjoy more music with an incredible 15 hours†battery-fueled fun. 只需剪辑一下,即可享受令人难以置信的15小时电池供电乐趣,享受更多音乐。 See what you’re listening to with the bright, easy-to-read screen and intuitively searchable menus. 明亮,易于阅读的屏幕和直观可搜索的菜单可让您看到正在聆听的内容。 Color your world in red, blue or sleek black undertones. 用红色,蓝色或光滑的黑色底色为您的世界增色。

NOTE: I tried preinheimer's suggestion, 注意:我尝试了preinheimer的建议,

First I tested it with a text file which worked well. 首先,我用一个效果很好的文本文件对其进行了测试。

$content = file_get_contents("test.txt");

echo htmlentities($content);

But when I tried the same thing dynamically it didn't work and left the text just the same. 但是,当我动态尝试相同的操作时,它不起作用,并且文本保持不变。

$content = $responseTemp->Items->Item->EditorialReviews->EditorialReview[$j]->Content;

echo htmlentities($content);

They both contain the same text but for some reason the dynamically version doesn't work. 它们都包含相同的文本,但是由于某种原因,动态版本不起作用。

ANOTHER UPDATE: I tried Juan's suggestion which is a slight improvement but still doesn't reproduce correctly, replacing many charecters with a question mark. 另一个更新:我尝试了Juan的建议,该建议稍有改进,但仍然无法正确复制,用问号代替了许多字符。 Here's what it gives me, 这就是它给我的,

The Sansa Clip+ MP3 player gives you more to enjoy. Sansa Clip + MP3播放器为您带来更多享受。 Enjoy up to 2,000 songs?? 欣赏多达2,000首歌曲? with an 8GB* player, FM radio, long-life battery and voice recorder. 配备8GB *播放器,FM收音机,长寿命电池和录音机。 PLUS now even more! 现在加更多! Expand your enjoyment when you add in preloaded content cards** into the new memory card slot, including slotRadio? 当您将预装的内容卡**添加到新的存储卡插槽(包括slotRadio)时,享受更多乐趣吗? and slotMusic? 和slotMusic? cards**. 牌**。 Or, save your own music, podcasts, and audio books onto a microSD?/microSDHC? 或者,将您自己的音乐,播客和有声读物保存到microSD?/ microSDHC? memory card** to expand your play.It?s brought to you by SanDisk with awesome sound to enjoy your music. 存储卡**,以扩大您的播放范围。SanDisk为您带来了震撼的声音,让您欣赏音乐。 Just clip it on and enjoy more music with an incredible 15 hours? 只需剪辑一下,享受令人难以置信的15个小时,欣赏更多音乐? battery-fueled fun. 电池驱动的乐趣。 See what you?re listening to with the bright, easy-to-read screen and intuitively searchable menus. 明亮,易于阅读的屏幕和直观可搜索的菜单可让您看到正在聆听的内容。 Color your world in red, blue or sleek black undertones. 用红色,蓝色或光滑的黑色底色为您的世界增色。

FINAL UPDATE: Aha, my mistake, I replaced $myOutputEncoding with 'utf-8' on Juan's example and add the following in the head tags to get it working, 最终更新:啊哈,我的错误,我在Juan的示例中将$ myOutputEncoding替换为'utf-8',并在head标签中添加了以下内容以使其正常运行,

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

It sounds like a character set issue. 听起来像是字符集问题。 Luckily, I wrote an article that got published today. 幸运的是,我写了一篇今天发表的文章。 http://phpadvent.org/2009/character-sets-by-paul-reinheimer http://phpadvent.org/2009/character-sets-by-paul-reinheimer

Check for a character set in the XML document (should be at the top, probably UTF-8), then try serving your page with the same character set. 检查XML文档中的字符集(应该在顶部,可能是UTF-8),然后尝试使用相同的字符集为页面提供服务。

Since you dont know the original encoding, you can try guessing with mb_detect_encoding like so 由于您不知道原始编码,因此可以尝试使用mb_detect_encoding猜测, mb_detect_encoding所示

$content = $responseTemp->Items->Item->EditorialReviews->EditorialReview[$j]->Content;
$encoding = mb_detect_encoding( $content );

$encodedText = mb_convert_encoding( $content, $myOutputEncoding, $encoding );

where $myOutputEncoding is the encoding you use. 其中$myOutputEncoding是您使用的编码。 Then when you output $encodedText it should show the text correctly. 然后,当您输出$encodedText它应该正确显示文本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM