phpQuery获取HTML图片
phpQuery获取HTML图片
/**
*获取html文本里的img
*@paramstring$contenthtml内容
*@returnarray图片列表数组item格式<pre>
*[
*"src"=>'图片链接',
*"title"=>'图片标签的title属性',
*"alt"=>'图片标签的alt属性'
*]
*</pre>
*/
functioncmf_get_content_images($content)
{
import('phpQuery.phpQuery',EXTEND_PATH);
\phpQuery::newDocumentHTML($content);
$pq=pq(null);
$images=$pq->find("img");
$imagesData=[];
if($images->length){
foreach($imagesas$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;
}


