【发布时间】:2017-12-19 15:33:32
【问题描述】:
我正在使用 php 版本 5.4.45 。 我在 php 版本 7 中测试此代码并且工作正常但在版本 5.4.45 中不工作
$string = '9301234567';
if( preg_match('/^\9\d{9}/', $string) )
{
$string = '0+1'.$string ;
return $string ;
}
在 v7 中返回:
0+19301234567
但在 v5.4.45 中返回(preg_match 返回 false)
9301234567
我如何在 php v5.4.45 中使用 preg_match('/^\9\d{9}/', $string) ?
谢谢
【问题讨论】:
-
使用
/^9\d{9}/ -
我已经在 3v4l.org/#preview 上测试了你的代码,它适用于 5.4.45。
-
转义单词字符没有意义,并导致未定义的行为。
标签: php regex preg-match