我可以使用Zend Dom Query来查询其他html属性,例如ALT

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

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']");