基本上我将2个文件存储到2个不同的数组中。第一个是我的模式,第二个是我的"主题"。
<?php
$file1 = fopen('file1.txt', 'r+');
$file2 = fopen('file2.geojson', 'r+');
while(!feof($file1)){
$buffer = fgets($file1);
$tab[] = $buffer;
}
while(!feof($file2)){
$buffer2 = fgets($file2);
$tab2[] = $buffer2;
}
for($j=0; $j<count($tab2);$j++){
for($i=0; $i<count($tab);$i++){
if(preg_match("#\"$tab[$i]\"#", $tab2[$j])){
echo "Found ! <br>";
echo $tab2[$j] . "<br>";
}
}
}
fclose($file1);
fclose($file2);
?>
问题只是&#39;标签中的最后一项&#39;被评估。我想我的正则表达式写得不好。
File1包含每行的邮政编码:
67810
67207
67980
67300
67204
67112
67117
67800
67203
&#13;
第二个文件是geojson,包含法国城市的所有地理位置。这是一个小例子:
{
"type": "FeatureCollection",
"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } },
"features": [
{ "type": "Feature", "properties": { "ID": "26140", "LIB": "Saint-Rambert-d'Albon", "DEP": "26", "SURF": 82.710226, "POP2010": 12812.000000, "_COL6": 5148.082000 }, "geometry": { "type": "MultiPolygon", "coordinates": [ [ [ [ 4.910952316875446, 45.239468880779881 ], [ 4.927807974060221, 45.236053935360097 ], [ 4.923509798950193, 45.238217934615989 ], [ 4.910952316875446, 45.233371738069984 ] ] ] ] } },
{ "type": "Feature", "properties": { "ID": "26150", "LIB": "Die", "DEP": "26", "SURF": 315.349961, "POP2010": 6301.000000, "_COL6": 3011.687900 }, "geometry": { "type": "MultiPolygon", "coordinates": [ [ [ [ 5.429793245468118, 44.703247891503587 ], [ 5.413013470624613, 44.688042393782084 ], [ 5.394637223225049, 44.687622044498482 ], [ 5.400643279242749, 44.678358831586564 ], [ 5.453052724102394, 44.704914679294212 ], [ 5.437312497288061, 44.700146412514492 ], [ 5.429793245468118, 44.703247891503587 ] ] ] ] } },
{ "type": "Feature", "properties": { "ID": "26160", "LIB": "La Begude-de-Mazenc", "DEP": "26", "SURF": 181.940199, "POP2010": 7285.000000, "_COL6": 3040.837200 }, "geometry": { "type": "MultiPolygon", "coordinates": [ [ [ [ 5.04538870963719, 44.610308524697103 ], [ 5.038809331299684, 44.59757761860763 ], [ 5.051232557215011, 44.603003224683015 ], [ 5.07330477638073, 44.59956580435167 ], [ 5.077375187960177, 44.592032286541126 ], [ 5.06659791007967, 44.584741592759165 ], [ 5.062893239233112, 44.56374699945075 ], [ 5.049501218954479, 44.557440600925943 ], [ 5.04538870963719, 44.559705577318169 ] ] ] ] } }
]
}
&#13;
我的目标是:每当我识别file2中file1的邮政编码时,我都会复制当前行并写入新的geojson文件。也许有更好的方法可以做到这一点?