dongshuao2309 2009-12-11 20:47
浏览 76
已采纳

显示一些字符的问题

I've got an XML file from which I've extracted the following text -

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. 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**. 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. Just clip it on and enjoy more music with an incredible 15 hours† 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.

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. 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**. 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. Just clip it on and enjoy more music with an incredible 15 hours†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.

NOTE: I tried preinheimer's suggestion,

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. Here's what it gives me,

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. 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**. 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. Just clip it on and enjoy more music with an incredible 15 hours? 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,

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

2条回答 默认 最新

  • doutong2132 2009-12-12 20:49
    关注

    Since you dont know the original encoding, you can try guessing with mb_detect_encoding like so

    $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. Then when you output $encodedText it should show the text correctly.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题