php怎么获取html字符串属性值
1、将img赋值个变量$str;$str='<img src="http://test.com/images/test.jpg" alt="test">';
2、去除html标签两端的 '<'和&拭貉强跳#39;>' 符号;$str = str_replace('<','媪青怍牙',str_replace('>','',$str));
3、然后在将$str以空格分隔成数组,赋值给$str_array;$str_array = explode(' ',$str);
4、定义数组$array,并且循环数组 $str_array,并将循环变量$s以'='符号分割,赋值给$ex;foreach ($str_array as $s){ $ex = explode('=',$s)}
5、如果$ex[1]存在,就以$ex[0]为键,$ex[1]为键值赋值给数组$array;foreach ($str_array as $s){ $ex = explode('=',$s); if(isset($ex[1])) { $array[$ex[0]] = str_replace('"','',$ex[1]); }}
6、输出你需要的html标签中需要的属性值。echo $array['src'];
声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
阅读量:26
阅读量:46
阅读量:41
阅读量:34
阅读量:53