How to return only named groups with preg_match or preg_match_all?

前端 未结 9 1384
余生分开走
余生分开走 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:07

    I use some of introduced codes and this is the final code works on php 5.6+:

    $re = '/\d+\r\n(?[\d\0:]+),\d+\s--\>\s(?[\d\0:]+),.*\r\nHOME.*\r\nGPS\((?[\d\.]+),(?[\d\.]+),(?[\d\.]+)\)\sBAROMETER\:(?[\d\.]+)/';
    
    $str= file_get_contents($srtFile);
    preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);
    echo '
    ';
    $filtered=array_map(function ($d){
         return $array_filtered = array_filter($d, "is_string", ARRAY_FILTER_USE_KEY);
        },$matches);
    var_dump($filtered);
    

    if you are interested what it does it read position data from a str file that DJI drones generate while recording video.

提交回复
热议问题