there is a test file of the form
(0:00) text1 text2 (0:30) text text text text text ..................
you need to get an array of the form key - this is the value in brackets, and the value is a test.
array("(0:00)"=>"text1 text2","(0:30)"=>"text text text text text")
I write the following:
$key = array(); $val = array(); $out = array(); $file = file('1.txt'); foreach($file as $line) { $line = trim($line); if (preg_match("/(\d{0,2}:\d\d)/",$line,$match)){ $key[]=$match; }else{ $val[]=$match; } $out=array_merge($key,$val); } echo '<pre>'; print_r($out);
tell me how to fix?
preg_match_all
- toxxxa