PHP 获取html文章中第一张图片;获取html汉字内容
/*
* 获取html内容第一张图片
* @ $content html内容
* */
function getFistImg($content){
$pattern="/<[img|IMG].*?src=[\'|\"](.*?(?:[\.gif|\.jpg|\.jpeg|\.png]))[\'|\"].*?[\/]?>/";
preg_match_all($pattern,htmlspecialchars_decode($content),$_Content);
$_contentImgSrc = !empty($_Content[1][0]) ? $_Content[1][0] : '默认图.png';
return $_contentImgSrc;
}
/*
* 获取html中的文字内容
* @ $content html内容
* */
function getContentText($content) {
// 移除html标签,第二个参数是排除指定的标签
$html = strip_tags($html);
return $html;
}