I’m using this code to get the alt attribute from img tags using domdocument. If a page has images without an alt attribute or if the alt attribute is empty it doesn’t recognize that. I need some help writing the conditions to check for empty alt attributes as well as none at all. Thanks
$name = trim($words->nodeName);
if($name == 'img' )
{
$alt= $words->getAttribute('alt');
if(!empty($alt))
{
$this->matchedAnchors[$this->count]['alt'] = trim($words->getAttribute('alt'));
You can use XPath for that:
Example:
will only print
Demo on codepad