php社区

php匹配字符串中url链接+替换

2020-07-23  本文已影响0人  jtw
$pattern = '`.*?((http|https)://[\w#$&+,\/:;=?@.-]+)[^\w#$&+,\/:;=?@.-]*?`i';
    if (preg_match_all($pattern,$url_string,$matches)) {
        print_r($matches[1]);
    }

得到如下数组:


image.png

用 str_ireplace 批量替换字符串中的url:

        $info['content'] = str_ireplace($arr,$url,$info['content']);
上一篇 下一篇

猜你喜欢

热点阅读