在我的一个PHP站点上,我使用这个正则表达式自动从字符串中删除电话号码:
如何确保上述
编辑: 按要求,这里有一个被
$text = preg_replace('/\+?[0-9][0-9()-\s+]{4,20}[0-9]/', '[removed]', $text);
但是,当用户发布包含多个数字作为其文本的长URL时,URL也会受到preg_replace
的影响,从而导致URL破坏。如何确保上述
preg_replace
不会改变$text
中包含的URL?编辑: 按要求,这里有一个被
preg_replace
破坏的URL示例:$text = 'Please help me with my question here: https://dev59.com/bnrZa4cB1Zd3GeqP0UOP Thanks!';
$text = preg_replace('/\+?[0-9][0-9()-\s+]{4,20}[0-9]/', '[removed]', $text);
echo $text;
//echoes: Please help me with my question here: https://stackoverflow.com/questions/[removed]/ Thanks!