PHP正则表达式匹配html标签属性值 50
<aid="btlist10"st="1"ditem="true"class="itemmulti-lineswith-avatar"ftios="1"ck="TlRZN...
<a id="btlist10" st="1" ditem="true" class="item multi-lines with-avatar" ftios="1" ck="TlRZNFlUSTRNakk9" ft="1" data="我想匹配的属性值" ix="10" analytical="false" s1="我想匹配的属性值2" jxd1="0781C99068C8FEBF" jxd2="69A2D6435ABEAF87817A812290560AB3" onclick="openmenu($(this))">
求大神帮忙写个规则 正则小白 谢谢了 展开
求大神帮忙写个规则 正则小白 谢谢了 展开
1个回答
2017-08-28
展开全部
<?php
$str = '<a id="btlist10" st="1" ditem="true" class="item multi-lines with-avatar" ftios="1" ck="TlRZNFlUSTRNakk9"
ft="1" data="我想匹配的属性值" ix="10" analytical="false" s1="我想匹配的属性值2"
jxd1="0781C99068C8FEBF" jxd2="69A2D6435ABEAF87817A812290560AB3" onclick="openmenu($(this))">';
$fun = function($str,$key){
$str=preg_replace("/[\s\S]*\s".$key."[=\"\']+([^\"\']*)[\"\'][\s\S]*/","$1",$str);
return $str;
};
$data = $fun($str, "data");
echo $data;
echo "\n";
$s1 = $fun($str, "s1");
echo $s1;
echo "\n";
$other = $fun($str, "ck");
echo $other;
echo "\n";
$other = $fun($str, "onclick");
echo $other;
?>
追问
如果我想取出多个属性值呢 能不能返回数组的 使用preg_match
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询