GeoffreyBernardo
-
Posts
1 -
Joined
-
Last visited
Never
We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.
Remove empty paragraphs from HTML file using simple_html_dom
in PHP Coding Help
Posted
I want to remove empty paragraphs from an HTML document using simple_html_dom.php. I know how to do it using the DOMDocument class, but, because the HTML files I work with are prepared in MS Word, the DOMDocument's loadHTMLFile() function gives this exception "Namespaces are not defined".
This is the code I use with the DOMDocument object for HTML files not prepared in MS Word:
This is the code I use with the simple_html_dom.php module for HTML files prepared in MS Word:
It is almost the same, except that that the $pars variable is a DOMNodeList when using DOMDocument and an array when using simple_html_dom.php. But this code does not work. First it runs for two minutes and then reports these errors: "Undefined offset: 1" and "Trying to get property of nonobject" for this line: "if (trim($pars[$i]->plaintext == "")) {".
Does anyone know how I can fix this?
Thank you.
I also asked on stackoverflow.