У меня есть этот кусок кода:
<?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
был определен, ноЯ не понимаю, почему возникла неопределенная ошибка индекса.