
PHP过滤字符串中URL地址
$content='测试字符串:http://www.feishuai.vip非常好。';
$content = preg_replace('/\<a.*?\>.*?<\/a>/i', '', $content);
$pattern = '`.*?((http|https)://[\w#$&+,\/:;=?@.-]+)[^\w#$&+,\/:;=?@.-]*?`i';
if (preg_match_all($pattern, $content, $matches)) {
if (preg_match_all("/<img[^<>]*src=[\"]([^\"]+)[\"][^<>]*>/im", $content, $imgMatches)) {
foreach ($matches[1] as $key => $url) {
if (in_array($url, $imgMatches[1])) {
unset($matches[1][$key]);
}
}
}
$content = str_ireplace($matches[1], '', $content);
}
var_dump($content);
声明:本文由用户投稿上传,本站不保证内容的真实与正确性,并且不承担相关法律责任,如有侵权请提供版权资料并联系删除!
编程笔记
»
PHP移除字符串中URL地址