【发布时间】:2011-04-25 11:18:47
【问题描述】:
示例 ini 文件是
[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),5c4ff70ac70b27d3
backuphash=285
[Size.JPG]
faces=rect64(f73101cd554ca7f),43cbda6e92fcb63e
backuphash=38150
[ints.jpg]
faces=rect64(45c213047999593c),e1059dcf6672a2b3
backuphash=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),43cbda6e92fcb63e
backuphash=9829
[karate.jpg]
faces=rect64(20823e7a6186b30b),15b6a967e857f334;rect64(92cb3e7ad34cb30b),15b6a967e857f334
backuphash=34154
模式算法
[$name_of_picture]
faces=rect64($hex1_1),$hex1_2;rect64($hex2_1),hex2_2;....rect64($hexn_1),hexn_2;
我有兴趣只阅读上面代码中由 $var_name.. 分配的部分。我该怎么办?
更新
使用解析ini
<?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);
?>
输出
警告:在 pic.ini 中解析错误 第 26 行 C:\tezt\up.php 中的第 2 行
警告:在 pic.ini 中解析错误 第 30 行 C:\tezt\up.php 中的第 2 行
更新2
<?php
function 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;
}
?>
输出
数组 ( [SAMPLE.jpg] => 数组 ( [面孔] => 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 [备份] => 285 ) [大小.JPG] => 数组([面孔] => rect64(f73101cd554ca7f),43cbda6e92fcb63e [备份] => 38150 ) [ints.jpg] => 数组([面孔] => rect64(45c213047999593c),e1059dcf6672a2b3 [备份] => 19801 ) [SC.jpg] => 数组([面孔] => 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 [备份] => 9829 ) [空手道.jpg] => 数组([面孔] => rect64(20823e7a6186b30b),15b6a967e857f334;rect64(92cb3e7ad34cb30b),15b6a967e857f334 [备份] => 34154 ) )
到目前为止一切顺利。谢谢你们。 这个问题与我的另一个问题有关 Automatic face detection using Picasa API to extract individual images
【问题讨论】: