preg_replace 找到 phone 个数字并删除空格
preg_replace find phone number and remove spaces
我有这个功能来查找 phone 数字并用可点击的 link 替换它们,我想从 phone 数字中删除空格,因为数字顺序在它是与 RTL(从右到左)文本混合:
$content_data = preg_replace('!(\b\+?[0-9()\[\]./ -]{7,17}\b|\b\+?[0-9()\[\]./ -]{7,17}\s+(extension|x|#|-|code|ext)\s+[0-9]{1,6})!i', '<a class="external text-ltr" href="tel:"></a>', $content_data);
我应该如何修改代码以从 phone 个数字中删除空格 ' '
?
谢谢。
怎么样:
已编辑:
$content_data = preg_replace_callback(
'!(\b\+?[0-9()\[\]./ -]{7,17}\b|\b\+?[0-9()\[\]./ -]{7,17}\s+(extension|x|#|-|code|ext)\s+[0-9]{1,6})!i',
function ($matches){
$tel=str_replace(" ", "", $matches[0]);
return '<a class="external text-ltr" href="tel:'.$tel.'">'.$tel.'</a>';
},
$content_data
);
我有这个功能来查找 phone 数字并用可点击的 link 替换它们,我想从 phone 数字中删除空格,因为数字顺序在它是与 RTL(从右到左)文本混合:
$content_data = preg_replace('!(\b\+?[0-9()\[\]./ -]{7,17}\b|\b\+?[0-9()\[\]./ -]{7,17}\s+(extension|x|#|-|code|ext)\s+[0-9]{1,6})!i', '<a class="external text-ltr" href="tel:"></a>', $content_data);
我应该如何修改代码以从 phone 个数字中删除空格 ' '
?
谢谢。
怎么样:
已编辑:
$content_data = preg_replace_callback(
'!(\b\+?[0-9()\[\]./ -]{7,17}\b|\b\+?[0-9()\[\]./ -]{7,17}\s+(extension|x|#|-|code|ext)\s+[0-9]{1,6})!i',
function ($matches){
$tel=str_replace(" ", "", $matches[0]);
return '<a class="external text-ltr" href="tel:'.$tel.'">'.$tel.'</a>';
},
$content_data
);