0

我试图在文件中搜索 nn/nnnnnn/nn..

我有这个

if (preg_match_all("([0-9]{6})", $file, $out)) {
echo "Match was found <br />";
print_r($out);

它处理中心 6 个数字,但我如何让它搜索整个模式?当我必须将搜索字符串添加在一起时,我有点困惑。我知道我必须执行以下操作

([0-9]{2}) 和 / 和 ([0-9]{6}) 和 / 和 ([0-9]{2})

如何将搜索字符串添加为一个?在此先感谢干杯垫

4

4 回答 4

2

你也可以用\d一个数字代替:

preg_match_all("#(\d{2})/(\d{6})/(\d{2})#", $string, $matches);
print_r($matches);
于 2013-01-19T17:44:54.040 回答
0

你有没有尝试过:

preg_match_all("/([0-9]{2})\/([0-9]{6})\/([0-9]{2})/")

例如,如果搜索12/123456/12,它将输出:

Array
(
    [0] => Array
        (
            [0] => 12/123456/12
        )

    [1] => Array
        (
            [0] => 12
        )

    [2] => Array
        (
            [0] => 123456
        )

    [3] => Array
        (
            [0] => 12
        )

)
于 2013-01-19T17:42:33.857 回答
0

试试这个#(\d{2})/(\d{6})/(\d{2})#

$file = '23/334324/23';
if (preg_match_all("#(\d{2})/(\d{6})/(\d{2})#", $file, $out)) {
    echo "Match was found <br />";
    print_r($out);
}

回报:

Array
(
    [0] => Array
        (
            [0] => 23/334324/23
        )

    [1] => Array
        (
            [0] => 23
        )

    [2] => Array
        (
            [0] => 334324
        )

    [3] => Array
        (
            [0] => 23
        )

)
于 2013-01-19T17:44:49.593 回答
0

如何使用#([0-9]{2})/([0-9]{6})/([0-9]{2})#

if(preg_match_all("#([0-9]{2})/([0-9]{6})/([0-9]{2})#", $file, $out)) 
{
    echo "Match was found <br />";
    print_r($out);
}
于 2013-01-19T17:45:09.457 回答