How to return only named groups with preg_match or preg_match_all?

前端 未结 9 1394
余生分开走
余生分开走 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条回答
  •  Happy的楠姐
    2020-12-09 11:23

    I read in your post that these are possible overloads of future memory etc ... In this case, why no't can be solved with an unset():

    $string = "This is some text written on 2010-07-18.";
    preg_match('|(?\d{4}-\d{2}-\d{2})|i', $string, $arr_result);
    $date = array("date" => $arr_result['date']);
    unset($arr_result, $string);//delete array and string preg_match origen
    
    print_r($date);
    //or create a new:
    //  $arr_result = $date;
    //print_r($arr_result);
    

提交回复
热议问题