duanbi9202 2012-09-27 14:46
浏览 14
已采纳

从php整理修复的html字符串中删除回车符

I would want check if string is a valid xhtml/html. I have some html string get by tinymce editor. I would want in first time before save it into mysql database check if this html string is valid. I'm trying php tidy library:

    $html = '<div> <a href="#">a link</a> this is test <p>close tag error</p> </p> <p></p>';
    $tidy = new \tidy();
    $clean = $tidy->repairString($html,array(
        'output-xml' => true,
        'input-xml' => true
    ));

but it output this:

<div>
<a href="#">a link</a>this is test 
<p>close tag error</p>other text 
<p></p></div>

so tags are closed correctly but tidy put /n characters. How can repair html without carriage return character?

  • 写回答

2条回答 默认 最新

  • duanfu1942 2012-09-27 15:00
    关注

    You need to use htmlspecialhars_decode() to disable displaying of special characters...

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

报告相同问题?