09月22日, 2014 4249次
拆分出html中 图片 链接和文本
不支持嵌套
可用于web 转化小程序数据
function get_item($op_contents){//
strip_tags($op_contents,"<img><a>");
$op_contents = str_replace("\n",'',$op_contents);
$op_contents = str_replace("\r",'',$op_contents);
$op_contents = preg_replace("/\<img[^>]+src=\"([^\"]+)\"[^>]*\>/i","[img]|||$1[/img]",$op_contents);
$op_contents = preg_replace("/\<p*?\>/i","<p>",$op_contents);
$op_contents = preg_split("/\[img\]|\[\/img\]/", $op_contents);
foreach ($op_contents as $items){
$tmp_item=(htmlspecialchars_decode( html_entity_decode($items)));
$tmp_item=str_replace("“","“",$tmp_item);
$tmp_item=str_replace("”","”",$tmp_item);
$tmp_item=str_replace("…","...",$tmp_item);
if(!empty($tmp_item)){
$op_contents_res[]=$tmp_item;
}
}
$op_contents_res_2="";
foreach ($op_contents_res as $op_contents_2){
$op_contents_2 = preg_replace("/\<A[^>]+HREF=\"([^\"]+)\"[^>]*\>(.*?)<\/a\>/i","[url]~~~$2~~~$1[/url]",$op_contents_2);
$op_contents_2 = preg_split("/\[url\]|\[\/url\]/", $op_contents_2);
if(!empty($op_contents_2)){
foreach($op_contents_2 as $v ){
$op_contents_res_2[]=strip_tags($v);
}
}
}
return $op_contents_res_2;
}
暂无留言,赶快评论吧