php 正则表达式 去除href及数据 20
1个回答
展开全部
$response = '<img src="https://gss0.bdstatic.com/70cFsjip0QIZ8tyhnq/img/logo-zhidao.gif" />'
.'基者早<a href="https://gss0.bdstatic.com/70cFsjip0QIZ8tyhnq/img/logo-zhidao.gif">查看百度知道LOGO</a>';
preg_match_all("/(href|src)=(["|']?)([^"'>]+.(jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG))/i",$response,$matches);
var_dump($matches);
执行后的结果为:
array(5) {
[0] => array(2) {
[0] => string(45) "src="https://gss0.bdstatic.com/70cFsjip0QIZ8tyhnq/img/logo-zhidao.gif"
[1] => string(46) "href="https://gss0.bdstatic.com/70cFsjip0QIZ8tyhnq/img/logo-zhidao.gif"
}
[1] => array(2) {
[0] => string(3) "src"
搏雀[1] => string(4) "href"
}
[2] => array(2) {
[0] => 嫌让string(1) """
[1] => string(1) """
}
[3] => array(2) {
[0] => string(40) "https://gss0.bdstatic.com/70cFsjip0QIZ8tyhnq/img/logo-zhidao.gif"
[1] => string(40) "https://gss0.bdstatic.com/70cFsjip0QIZ8tyhnq/img/logo-zhidao.gif"
}
[4] => array(2) {
[0] => string(3) "gif"
[1] => string(3) "gif"
}
}
这是正则匹配的部分,怎么去除就交给你了
参考:
PHP笔记(一):如何利用正则匹配图片路径
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询