Jump to content

loadHTML problem


fanfavorite

Recommended Posts

I am using loadHTML to get the contents of a section of code that is edited and getting the img tags from it.  The reason for this is I need to check for the image "src, width, height".  If there is a width and height, we change it if it is too large for the page.  If there is no width and height tags, we read the image and get the dimensions, and add width and height tags if it is too large.  The way I am reading the content string is:

 

$doc=new DOMDocument();

$doc->loadHTML($content);

$xml=simplexml_import_dom($doc);

$images=$xml->xpath('//img');

 

Now I run into errors sometimes:

 

PHP Warning:  DOMDocument::loadHTML() [<a href='domdocument.loadhtml'>domdocument.loadhtml</a>]: error parsing attribute name in Entity, line: 1

PHP Warning:  DOMDocument::loadHTML() [<a href='domdocument.loadhtml'>domdocument.loadhtml</a>]: error parsing attribute name in Entity, line: 2

 

<p><span style="font-size: x-small;"><a href="somelink.php">Some Text</a></span></p>

<p><span style="font-size: x-small;">Some Other Text<a href="somelink.php">Some Text</a></span></p>

 

Does anyone have a workaround to not get these errors?

 

Thanks,

 

-JC

Link to comment
https://forums.phpfreaks.com/topic/143473-loadhtml-problem/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

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.