简体   繁体   中英

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

如何使用Ko3或PHP从HTML部分获取所有图像标签?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM