<p>I would like to create a page where all images which reside on my website are listed with title and alternative representation.</p>

<p>I already wrote me a little program to find and load all HTML files, but now I am stuck at how to extract <code>src</code>, <code>title</code> and <code>alt</code> from this HTML:</p>

<pre><code>&lt;img <b>src</b>="/image/fluffybunny.jpg" <b>title</b>="Harvey the bunny" <b>alt</b>="a cute little fluffy bunny" /></code></pre>

<p>I guess this should be done with some regex, but since the order of the tags may vary, and I need all of them, I don't really know how to parse this in an elegant way (I could do it the hard char by char way, but that's painful).</p>

Just to give a small example of using PHP's XML functionality for the task:
```
```
$doc=new DOMDocument();
$doc->loadHTML("<html><body>Test<br><img src=\"myimage.jpg\" title=\"title\" alt=\"alt\"></body></html>");
$xml=simplexml_import_dom($doc); // just to make xpath more simple
$images=$xml->xpath('//img');
foreach ($images as $img) {
    echo $img['src'] . ' ' . $img['alt'] . ' ' . $img['title'];
}
```
```
I did use the
```
DOMDocument::loadHTML()
```
method because this method can cope with HTML-syntax and does not force the input document to be XHTML. Strictly speaking the conversion to a
```
SimpleXMLElement
```
is not necessary - it just makes using xpath and the xpath results more simple.