0
votes

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
Pass it though domdocument, 3v4l.org/bEWQO then it will render the broken bits htmlentities, so your outer DOM is ok.Lawrence Cherone
Thanks for the answer. I try this code in my site. It gave me error.prince sharma
What error did it give?Lawrence Cherone
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();prince sharma
It still gives the same error: Warning: DOMDocument::loadHTML() expects parameter 2 to be long, string given on line 42prince sharma

1 Answers

0
votes

You can use Tidy

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