本帖最后由 gxuc2008 于 2012-06-19 17:12:32 编辑

解决方案 »

  1.   

    用正则<?php
    $str = "[任意文字]120巷[任意文字]110号";
    preg_match_all("/(\d+)/", $str, $match);
    print_r($match);
    ?>
      

  2.   

    $str = "55[任意文字]120巷[任意文字]110号55";
    preg_match_all("/(?<=任意文字\])(\d+)/", $str, $match);
    print_r($match[1]);
      

  3.   

    [User:root Time:06:06:22 Path:/home/liangdong/php]$ php preg.php 
    Array
    (
        [0] => [任意内容]120巷[任意内容]110
        [1] => 120
        [2] => 110
    )
    [User:root Time:06:06:23 Path:/home/liangdong/php]$ cat preg.php 
    <?php
    $content = <<<EOF
    [任意内容]120巷[任意内容]110号
    EOF;
    $nmatches = preg_match('/\[.*\]((?-U)\d+).*\[.*\]((?-U)\d+).*/iUs', $content, $matches);
    print_r($matches);
    ?>