2012-11-30 213 views
0
$response = curl_exec($ch); 
    curl_close($ch); 
    //Split the HEADERS and BODY 
    list($h, $EALOGIN) = explode("\r\n\r\n", $response, 2); 
    $r = explode("\r\n", $h); 

    //EASW Key 
    $s = explode(":", $r[7]); 
    $t = explode(";", $s[1]); 
    $EASW_KEY = $t[0]; 
    //Session Key 
    $m = explode(":", $r[8]); 
    $n = explode(";", $m[1]); 
    $EASF_SESS = $n[0]; 
    //nuc 
    $a = explode("<nucleusId>", $EALOGIN); 
    $b = explode("</nucleusId>", $a[1]); 
    $NUC = $b[0]; 

脫機指的是「$ a」行。 我不明白這個錯誤。 我該如何解決它?未定義偏移量:1 php

+0

看看這裏:http://stackoverflow.com/questions/5400332/php-error-undefined -offset-1 – SenorAmor

+2

這可能不是一個錯誤。仔細觀察,這是一個警告! $ a僅包含一個索引爲「0」的單個元素。所以'$ a [1]'不存在。 – arkascha

回答

1

這個問題可能是由於沒有設置$a[1]

分隔符可能不是在這個語句中找到:

$a = explode("<nucleusId>", $EALOGIN); 

嘗試使用調試語句(的var_dump()的,等等),並用代碼試驗,以找出問題的根源。

0

「未定義偏移量」表示某些數組沒有帶特定鍵的元素。它可能是$a陣列。

我建議調試這樣的代碼:

$response = curl_exec($ch); 
curl_close($ch); 
//Split the HEADERS and BODY 
list($h, $EALOGIN) = explode("\r\n\r\n", $response, 2); 
$r = explode("\r\n", $h); 

//EASW Key 
$s = explode(":", $r[7]); 
$t = explode(";", $s[1]); 
$EASW_KEY = $t[0]; 
//Session Key 
$m = explode(":", $r[8]); 
$n = explode(";", $m[1]); 
$EASF_SESS = $n[0]; 
//nuc 
$a = explode("<nucleusId>", $EALOGIN); 

// debug start 
echo "<pre>"; 
print_r($a); 
echo "</pre>"; 
// debug end 

$b = explode("</nucleusId>", $a[1]); 
$NUC = $b[0]; 
0

嘗試它的preg_match

$pattern = "/<nucleusId>(.*)<\/nucleusId>/"; 
preg_match($pattern, $string, $matches); 
$NUC = $matches[1];