/**
* 将html文字和图片分类成数组
* @param $str
* @return array
*/
public static function spiltHtml($str){
$content = stripslashes(strip_tags($str, "<img>"));
preg_match_all('/<img.*?src=["|\'](.*?)["|\']/',$content, $match);
$imgs = $match[1];
$res = preg_split('/<img(.*?)>/',$content);
foreach ($res as $key => $value) {
if($value != ""){
$result[] = array(
'type' => 'text',
'text' => htmlspecialchars($value, ENT_QUOTES, 'utf-8')
);
}
if(!empty($imgs[$key])){
$src = htmlspecialchars($imgs[$key], ENT_COMPAT , 'utf-8');
$result[] = array(
'type' => 'img',
'src' => $src
);
}
}
return $result;
}
将图片拆分成数组行是