phpQuery获取HTML图片
phpQuery获取HTML图片
/** * 获取html文本里的img * @param string $content html 内容 * @return array 图片列表 数组item格式<pre> * [ * "src"=>'图片链接', * "title"=>'图片标签的 title 属性', * "alt"=>'图片标签的 alt 属性' * ] * </pre> */ function cmf_get_content_images($content) { import('phpQuery.phpQuery', EXTEND_PATH); \phpQuery::newDocumentHTML($content); $pq = pq(null); $images = $pq->find("img"); $imagesData = []; if ($images->length) { foreach ($images as $img) { $img = pq($img); $image = []; $image['src'] = $img->attr("src"); $image['title'] = $img->attr("title"); $image['alt'] = $img->attr("alt"); array_push($imagesData, $image); } } \phpQuery::$documents = null; return $imagesData; }