我有这样一段代码:故障排除“通知:未定义指数”,但指数似乎被定义
<?php
$pattern = "/<span\b[^>]*>(.*?)</";
$html = file_get_contents("http://www.bicicletapublica.com.ar/mapa.aspx");
$results = array();
preg_match_all($pattern, $html, $results);
$results = $results[0];
$stations = array();
for($i = 0; $i < count($results)-1;$i++){
if(!($i & 1)){
$key = strtolower(str_replace(" ","_",substr($results[$i], 0, -1)));
$stations["$key"] = str_replace("Cant. Bicicletas disponibles: ","",substr($results[$i+1], 0, -1));
}
}
print_r($stations);
print_r($stations["retiro"])
?>
而且我得到这个错误:
Array ([retiro] => 40 [aduana] => 26 [derecho] => 27 [plaza_roma] => 8 [plaza_italia] => 29 [parque_lezama] => 31 [obelisco] => 28 [congreso] => 7 [parque_las_heras] => 17 [uca_puerto_madero] => 27 [tribunales] => 25 [plaza_vicente_lopez] => 23 [once] => 27 [pacifico] => 19 [virrey_cevallos] => 26 [plaza_houssay] => 2 [plaza_de_mayo] => 6 [plaza_almagro] => 21 [cmd] => 7 [independencia] => 9 [plaza_san_martin] => 21)
Notice: Undefined index: retiro in /opt/lampp/htdocs/mejorenbici/index.php on line 17
正如你所看到的,密钥retiro
已定义,但我不明白为什么会触发未定义的索引错误。
这里有更多故事。 PHP文件中的任何有趣的字符?你没有在你的阵列上使用unicode索引,对吧?此外,不需要在'$ stations [“$ key”] = str_replace(...'。 – Brad
@Brad - >当我在我的网站上运行该代码时,我也会得到相同的错误数组中的所有按键 –
@JaredFarrish,PointedEars在下面列出了它,对于Topicus和你来说,不要给我们错误,就像浏览器呈现的那样......还有更多的东西,那是隐藏的,查看源显示 – Brad