php正则怎么去掉href

来自:互联网
时间:2021-11-24
阅读:

php正则怎么去掉href?

问题描述:

php 正则表达式 去除href及数据

要把这段<a target="_blank" href="./Itemxteal_8000-0000_1.htm">8000-0000</a>

替换为<a target="_blank" >8000-0000</a>

链接不唯一 就是去掉href=“XXXXX”

要怎么写??

实现方法:

<?php
$string = '<a target="_blank" href="./Itemxteal_8000-0000_1.htm">8000-0000</a>';
preg_match('/href\s*=\s*(?:"([^"]*)"|\'([^\']*)\'|([^"\'>\s]+))/is', $string,$matches);
//print_r($matches);
echo str_replace($matches[0], '', $string);
?>
返回顶部
顶部