电话号码的正则表达式有一些问题,到目前为止它可以工作,但我不知道如何用空格替换“//”:
输入:0()()()111 1-11* // *1111
预计:: +49 111 111 1111
得到:+49 111 1111111
$pattern = array(
'/[^0-9\+\.\-\(\) ]/', // Cut all characters that are not allowed
'/^00/', // Start with 00 ist changed to +
'/^(0)(\d)/', // Start with 0[1-9] ist changed to +49 [0-9]
'/[\.\-\(\)]/', // Change allowed characters to ' '
'/\s[\s]+/', // Change grouped spaces too one
'/((\+49 )(0))(.*)/'
);
$change = array('', '+', '+49 $2', ' ', ' ', '$2$4');
$value = preg_replace($pattern, $change, $value);
将字符添加到:
'/[\.\-\(\)]/', // Change allowed characters to ' '
这是行不通的。抱歉,我对正则表达式的了解有限。