CSV ファイルから MAC アドレスと場所を読み取るスクリプトを作成しています。問題は、preg_match_all を 2 回使用していることです。1 つ目は、MAC アドレスを見つけることです。2 つ目は、場所が書き込まれる形式に基づいています。私はそれらを入れ替えたので、実際には両方の正規表現が機能することを知っています。
次のような出力を取得しようとしています:
The Mac Address 0c:85:25:c7:ab:f0 is located in Tilburg-Compleet > P1 > P1-2e
しかし、私が今受け取っている出力は次のとおりです。
The Mac Address 0c:85:25:c7:ab:f0 is located in
助けてください?
よろしく、ブライアン
<?php
if (($handle = fopen("AP_Summary_20121004_104813_198.csv", "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$num = count($data);
for ($i=0; $i < $num; $i++) {
$m = preg_match_all('~[0-9a-f]{2}[:-][0-9a-f]{2}[:-][0-9a-f]{2}[:-][0-9a-f]{2}[:-][0-9a-f]{2}[:-][0-9a-f]{2}~', $data[$i], $match);
$c = preg_match_all('~^.{1,}\s\W\s.{1,}\s\W\s$~', $data[$i], $matches);
if ($m) {
foreach ($match as $val){
foreach ($matches as $values){
echo 'The Mac Address <b>' . $val[0] . '</b> is located in <b>' . $values[0] . '</b><br /><br />';
}
}
}
}
}
fclose($handle);
}
?>
CSV ファイルの一部を次に示します。
EHV-R1-1e-109113 ,d8:24:bd:e9:ce:f0 ,Eindhoven-rachelsemolen-TUE-TF > R1 > R1-1e ,Enabled
EHV-R1-1e-109117 ,d8:24:bd:e9:e6:40 ,Eindhoven-rachelsemolen-TUE-TF > R1 > R1-1e ,Enabled
EHV-R1-1e-109118 ,d8:24:bd:e9:ed:b0 ,Eindhoven-rachelsemolen-TUE-TF > R1 > R1-1e ,Enabled
Ehv-R1-2e-27088 ,00:12:44:ba:1e:00 ,Eindhoven-rachelsemolen-TUE-TF > R1 > R1-2e ,Enabled
Ehv-R1-2e-27090 ,00:12:44:ba:1f:b0 ,Eindhoven-rachelsemolen-TUE-TF > R1 > R1-2e ,Enabled
Ehv-R1-2e-27086 ,00:12:44:ba:20:c0 ,Eindhoven-rachelsemolen-TUE-TF > R1 > R1-2e ,Enabled
Ehv-R1-2e-27087 ,00:12:44:ba:21:40 ,Eindhoven-rachelsemolen-TUE-TF > R1 > R1-2e ,Enabled
Ehv-R1-2e-27084 ,00:12:44:ba:2b:10 ,Eindhoven-rachelsemolen-TUE-TF > R1 > R1-2e ,Enabled
Ehv-R1-2e-27085 ,00:12:44:ba:32:a0 ,Eindhoven-rachelsemolen-TUE-TF > R1 > R1-2e ,Enabled
Ehv-R1-2e-27094 ,00:12:44:ba:77:10 ,Eindhoven-rachelsemolen-TUE-TF > R1 > R1-2e ,Enabled
Ehv-R1-2e-63664 ,00:1b:8f:89:28:c0 ,Eindhoven-rachelsemolen-TUE-TF > R1 > R1-2e ,Enabled
Ehv-R1-2e-100264 ,00:3a:98:62:ae:a0 ,Eindhoven-rachelsemolen-TUE-TF > R1 > R1-2e ,Enabled
Ehv-R1-2e-100266 ,00:3a:98:62:af:e0 ,Eindhoven-rachelsemolen-TUE-TF > R1 > R1-2e ,Enabled
Ehv-R1-2e-100263 ,00:3a:98:72:b6:40 ,Eindhoven-rachelsemolen-TUE-TF > R1 > R1-2e ,Enabled
Ehv-R1-2e-100265 ,00:3a:98:72:b9:f0 ,Eindhoven-rachelsemolen-TUE-TF > R1 > R1-2e ,Enabled
Ehv-R1-2e-100261 ,00:3a:98:72:ba:f0 ,Eindhoven-rachelsemolen-TUE-TF > R1 > R1-2e ,Enabled