我想使用的PHP項目2.2.2天氣,但它有很多問題 這裏是一個代碼爲什麼在PHP這個消息來了:通知未定義,偏移量:2
function get_languages($type) {
static $output = array();
if (empty($output)) {
/* I use dirname(__FILE__) here instead of PHPWEATHER_BASE_DIR
* because one might use this function without having included
* phpweather.php first. */
require(dirname(__FILE__) . '/languages.php');
$dir = opendir(dirname(__FILE__) . '/output');
while($file = readdir($dir)) {
// I got a problem in this line below
if (ereg("^pw_${type}_([a-z][a-z])(_[A-Z][A-Z])?\.php$", $file, $regs)) {
// After i change it to the line mentioned below i got error undefined offset:2 in line 2 mentioned below
// how to correct this error or is there any way to correct this code
if(preg_match("#^pw_${type}_([a-z][a-z])(_[A-Z][A-Z])?\.php$#", $file, $regs)) {
$output[$regs[1] . $regs[2]] = $languages[$regs[1] . $regs[2]];
}
}
closedir($dir);
}
asort($output);
return $output;
}
您確定$ regs [2]是否存在? – Joshua
'var_dump($ regs);'你會得到你的答案。 – Rikesh
感謝您的幫助:) – user1991