Regex for Reading ini with PHP

uggschuhenztuf

New Member
Sample ini file is\[code\][SAMPLE.jpg]faces=rect64(c18f4c8ef407851e),d4ff0a020be5c3c0;rect64(534a06d429ae627),dff6163dfd9d4e41;rect64(b9c100fae46b3046),e1059dcf6672a2b3;rect64(7b5105daac3a3cf4),4fc7332c107ffafc;rect64(42a036a27062a6c),ef86c3326c143248;rect64(31f4efe3bd68fd8),90158b3d3b65dc9b;rect64(327904e0614d390d),43cbda6e92fcb63e;rect64(4215507584ae9b8c),15b6a967e857f334;rect64(895d4efeb8b68425),5c4ff70ac70b27d3backuphash=285[Size.JPG]faces=rect64(f73101cd554ca7f),43cbda6e92fcb63ebackuphash=38150[ints.jpg]faces=rect64(45c213047999593c),e1059dcf6672a2b3backuphash=19801[SC.jpg]faces=rect64(993f2dfdab7f5166),e1059dcf6672a2b3;rect64(4b002f365a004c1b),ef86c3326c143248;rect64(bbffbb9fcb7fda25),ef86c3326c143248;rect64(bbbf9b10cb7fb996),90158b3d3b65dc9b;rect64(bbffdc97cb3ffa4c),4fc7332c107ffafc;rect64(5ec0306f734058b9),43cbda6e92fcb63e;rect64(65c06969827fa12b),15b6a967e857f334;rect64(bbff59f2cbbf7878),15b6a967e857f334;rect64(bbff7a81cb3f989f),43cbda6e92fcb63ebackuphash=9829[karate.jpg]faces=rect64(20823e7a6186b30b),15b6a967e857f334;rect64(92cb3e7ad34cb30b),15b6a967e857f334backuphash=34154\[/code\]Algorithm for pattern\[code\][$name_of_picture]faces=rect64($hex1_1),$hex1_2;rect64($hex2_1),hex2_2;....rect64($hexn_1),hexn_2;\[/code\]I am interested in reading only the parts that are assigned by $var_name.. in the above code. How do I go about it?UpdateUsing parse ini\[code\]<?php//code from php.net// Parse without sections$ini_array = parse_ini_file("pic.ini");print_r($ini_array);// Parse with sections$ini_array = parse_ini_file("pic.ini", true);print_r($ini_array);?>\[/code\]Output\[quote\] Warning: parse error in pic.ini on line 2 in C:\tezt\up.php on line 26 Warning: parse error in pic.ini on line 2 in C:\tezt\up.php on line 30\[/quote\]Update2\[code\]<?phpfunction new_parse_ini($f){ // if cannot open file, return false if (!is_file($f)) return false; $ini = file($f); // to hold the categories, and within them the entries $cats = array(); foreach ($ini as $i) { if (@preg_match('/\[(.+)\]/', $i, $matches)) { $last = $matches[1]; } elseif (@preg_match('/(.+)=(.+)/', $i, $matches)) { $cats[$last][$matches[1]] = $matches[2]; } } return $cats;}?>\[/code\]Output\[quote\] Array ( [SAMPLE.jpg] => Array ( [faces] => rect64(c18f4c8ef407851e),d4ff0a020be5c3c0;rect64(534a06d429ae627),dff6163dfd9d4e41;rect64(b9c100fae46b3046),e1059dcf6672a2b3;rect64(7b5105daac3a3cf4),4fc7332c107ffafc;rect64(42a036a27062a6c),ef86c3326c143248;rect64(31f4efe3bd68fd8),90158b3d3b65dc9b;rect64(327904e0614d390d),43cbda6e92fcb63e;rect64(4215507584ae9b8c),15b6a967e857f334;rect64(895d4efeb8b68425),5c4ff70ac70b27d3 [backuphash] => 285 ) [Size.JPG] => Array ( [faces] => rect64(f73101cd554ca7f),43cbda6e92fcb63e [backuphash] => 38150 ) [ints.jpg] => Array ( [faces] => rect64(45c213047999593c),e1059dcf6672a2b3 [backuphash] => 19801 ) [SC.jpg] => Array ( [faces] => rect64(993f2dfdab7f5166),e1059dcf6672a2b3;rect64(4b002f365a004c1b),ef86c3326c143248;rect64(bbffbb9fcb7fda25),ef86c3326c143248;rect64(bbbf9b10cb7fb996),90158b3d3b65dc9b;rect64(bbffdc97cb3ffa4c),4fc7332c107ffafc;rect64(5ec0306f734058b9),43cbda6e92fcb63e;rect64(65c06969827fa12b),15b6a967e857f334;rect64(bbff59f2cbbf7878),15b6a967e857f334;rect64(bbff7a81cb3f989f),43cbda6e92fcb63e [backuphash] => 9829 ) [karate.jpg] => Array ( [faces] => rect64(20823e7a6186b30b),15b6a967e857f334;rect64(92cb3e7ad34cb30b),15b6a967e857f334 [backuphash] => 34154 ) )\[/quote\]So far so good. Thank you guys.This question is related to another question of minehttp://stackoverflow.com/questions/3872112/automatic-face-detection-using-api
 
Back
Top