本帖最后由 evanhaha 于 2011-07-06 10:57:27 编辑

解决方案 »

  1.   


    $str= <<<HTML
    abc/def/ghi/123456.shtml
    abc/def/123456.shtml
    abc/123456.shtmlabc/def/987/123456.shtml
    abc/654/123456.shtml
    321/123456.shtml
    HTML;
    preg_match_all('/\/(\d+)\.shtml/isU',$str,$matches);
    print_r($matches[1]);Array
    (
        [0] => 123456
        [1] => 123456
        [2] => 123456
        [3] => 123456
        [4] => 123456
        [5] => 123456
    )
      

  2.   


    $strArray = array("abc/def/ghi/123456.shtml","abc/def/123456.shtml","abc/123456.shtml","abc/def/987/123456.shtml","abc/654/123456.shtml","321/123456.shtml");
    foreach($strArray as $str){
    preg_match("/([\w]+).shtml$/i",$str,$matchs);
    print_r($matchs[1]."\r\n");
    }