douzhi7070 2012-02-15 19:57
浏览 6

XML中的HTML而不破坏有效性

I was hoping someone can help me with the following issue. As I am at a brick wall after a day on this.

I am trying to take products descriptions from an online shops database and produce an XML feed. The problem is the descriptions contain HTML so the XML breaks when viewing it in a browser

This is the line of code:-

echo    '<DESCRIPTION>' . $row['products_description'] . '</DESCRIPTION>';

I have tried the following:-

echo    '<DESCRIPTION><![CDATA[' . $row['products_description'] . ']]></DESCRIPTION>';   

When i view the output it breaks the XML at the first

<BR>

I am aware of the htmlentities in PHP but this doesn't work as I pick up the XML from another shop to import the descriptions and they Wont display correctly when imported back in

I hope someone can help. Thanks for taking the time to look

  • 写回答

1条回答 默认 最新

  • dongyu1979 2012-02-15 20:16
    关注

    Tidy the HTML first.

    $config = array(
      'indent'         => true,
      'output-xhtml'   => true,
      'wrap'           => 200);
    
    $tidy = new Tidy();
    $tidy->parseString($row['products_description'], $config, 'utf8');
    $tidy->cleanRepair();
    
    echo    '<DESCRIPTION>' . $tidy. '</DESCRIPTION>';
    

    You will need to have the libtidy extension installed for this to work.

    评论

报告相同问题?

悬赏问题

  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程