0

Using Zend Dom Query I would like to search HTML to find certain attributes.

Take the following image as an example.

<img id="active-main-image"  src="/images/example.jpg" alt="Image 1234" class="product-image">

Instead of using $this->_xhtml->query('img#active-main-image'); I would like to find the image by using the alt attribute.

Pseudo -> $this->_xhtml->query('img alt Image 1234');

I can see why this method is not conventionally popular however, when equipped with nothing but the Alt value of a certain image on a page, I see no alternative.

Thanks

David Sigley
  • 1,126
  • 2
  • 13
  • 28

1 Answers1

2

Zend_Dom_Query has a queryXpath method that will accept valid xpath queries.

Untested but this should work :

$dom = new Zend_Dom_Query($html);
$img = $dom->queryXpath("//img[@alt='Image 1234']");
piddl0r
  • 2,431
  • 2
  • 23
  • 35