这是我正在阅读的文本文件的内容
All Guests Listed Below
ID: SeanCarrington [x]
Name: Sean [x]
Email: Carrington [x]
ID: ChrisCarrington [x]
Name: Chris [x]
Email: Carrington [x]
我想提取每个客人的 ID,所以我写了这个
preg_match_all("/(ID: )(.*)(\[x\])/", $fileContent, $matches);
一个 print_r$fileContent
给了我这个
Array ( [0] => Array ( [0] => ID: SeanCarrington [x] [1] => ID: ChrisCarrington [x] ) [1] => Array ( [0] => ID: [1] => ID: ) [2] => Array ( [0] => SeanCarrington [1] => ChrisCarrington ) [3] => Array ( [0] => [x] [1] => [x] ) )
我的目标是打印出每个用户的第 2 组。换句话说,他们的 ID。所以目标输出是
SeanCarrington
ChrisCarrington
我试过这个
echo $matches[0][2];
echo $matches[1][2];
但我得到这个错误
Notice: Undefined offset: 2 in /data/helios_web/ccarrin2/IT207/lab9/convertToArray.php on line 10
Notice: Undefined offset: 2 in /data/helios_web/ccarrin2/IT207/lab9/convertToArray.php on line 11