tags:

views:

35

answers:

1

how to use Ko3 or PHP get all image tags from a section of HTML?

+1  A: 

I would use xPath with SimpleXml or DOMDocument depending on my needs, although Kohana might offer something better like Zend does with Zend_Dom_Query or Symfony does with sfWebBrowser (both of which let you use a querys similar to jQuery's css selectors). Anyhow with simple xml it might look like the following:

// we will assume you want the images in a div with the id "ihaveimages"

$dom = new SimpleXmlElement($htmlString);
$images = $dom->xpath("//div[@id='ihaveimages']/img");

foreach($images as $image)
{
  echo $image->asXml();
}

More info on xPath

prodigitalson