douxi8119 2018-07-19 05:36
浏览 64

当用户在CKeditor的源代码中打开一些标签或引号时如何解决?

I am inserting data in MySQL with CKeditor and PHP. I am taking raw HTML from the user side. If the user leaves some quotes or tags open then how could I handle this problem?

For example, if users inputs in source of ckeditor and leaves quotes open, then how to solve this in PHP?

<p style="color:red;> Some Content </p>

Here is my code

And the HTML string is save in $postObj->post_content.

I am getting this error:

Warning: DOMDocument::loadHTML() expects parameter 2 to be long, string given on line 55 and here is my code ... libxml_use_internal_errors(true); $dom = new DOMDocument(); $dom->loadHtml($postObj->post_content, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD); $cont = $dom->saveHTML().PHP_EOL; $res = $common->findFirstPara($cont,$ad_content); libxml_clear_errors();

  • 写回答

1条回答 默认 最新

  • douzhang6646 2018-07-19 12:27
    关注

    You can use Tidy

    $html = '<p style="color:red;> Some Content </p>';
    $tidy = tidy_parse_string($html);
    $tidy->cleanRepair();
    return $tidy;
    
    评论

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀