How to return only named groups with preg_match or preg_match_all?

前端 未结 9 1398
余生分开走
余生分开走 2020-12-09 10:51

Example:

$string = \"This is some text written on 2010-07-18.\";
preg_match(\'|(?\\d\\d\\d\\d-\\d\\d-\\d\\d)|i\', $string, $arr_result);
print_r(         


        
9条回答
  •  庸人自扰
    2020-12-09 11:20

    It also possible to unset all numeric indexes before return:

    foreach (range(0, floor(count($arr_result) / 2)) as $index) {
        unset($arr_result[$index]);
    }
    

提交回复
热议问题