php 正则表达式怎么把图片URL匹配出来呢?
php正则表达式怎么把图片URL匹配出来呢?<imgdatasrc="http://mm.baidu.com/mmbiz/icUjHZK538gJJrdYUWUoicJ5...
php 正则表达式怎么把图片URL匹配出来呢?
<img data src="http://mm.baidu.com/mmbiz/icUjHZK538gJJrdYUWUoicJ5wicwIp3uNiatpw0CtzrKQT0C6LemQRuPSiaq0R01pkPs0I2ItUdTx3iamOFK8QVqofnQ/640?tp=webp" data-s="300,640" data-ratio="0.625" data-w="400" style="box-sizing: border-box !important; width: auto !important; word-wrap: break-word !important; visibility: visible !important;" /> 展开
<img data src="http://mm.baidu.com/mmbiz/icUjHZK538gJJrdYUWUoicJ5wicwIp3uNiatpw0CtzrKQT0C6LemQRuPSiaq0R01pkPs0I2ItUdTx3iamOFK8QVqofnQ/640?tp=webp" data-s="300,640" data-ratio="0.625" data-w="400" style="box-sizing: border-box !important; width: auto !important; word-wrap: break-word !important; visibility: visible !important;" /> 展开
展开全部
使用preg_match_all函数,即可实现你的要求。代码如下:
$str = '<img data src="http://mm.baidu.com/mmbiz/icUjHZK538gJJrdYUWUoicJ5wicwIp3uNiatpw0CtzrKQT0C6LemQRuPSiaq0R01pkPs0I2ItUdTx3iamOFK8QVqofnQ/640?tp=webp" data-s="300,640" data-ratio="0.625" data-w="400" style="box-sizing: border-box !important; width: auto !important; word-wrap: break-word !important; visibility: visible !important;" />';
$pattern = '/<img.*src="(.*?)"/';
preg_match_all($pattern,$str,$matches);
echo $matches[1][0];
//返回:http://mm.baidu.com/mmbiz/icUjHZK538gJJrdYUWUoicJ5wicwIp3uNiatpw0CtzrKQT0C6LemQRuPSiaq0R01pkPs0I2ItUdTx3iamOFK8QVqofnQ/640?tp=webp
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询