[英]Getting error: Undefined offset: 1
看起來一切正常。 它也顯示結果,但同時顯示Undefined offset:1錯誤。 請幫我解決一下這個。
$url = "http://www.test.com";
$pageContent = file_get_contents($url);
$stepA = explode("</title>",$pageContent);
$stepB = explode("<title>",$stepA[0]);
$stepC = $stepB[1];
if($stepC == "Not Found"){
echo $stepC = "NA";
} else{
echo $stepC = "ok";
}
添加一些類似下面的代碼:
$url = "http://www.test.com";
$pageContent = file_get_contents($url);
$stepA = explode("</title>",$pageContent);
if(isset($stepA)) {
$stepB = explode("<title>",$stepA[0]);
$stepC = isset($stepB) ? $stepB[1] : null;
if($stepC == "Not Found"){
echo $stepC = "NA";
} else{
echo $stepC = "ok";
}
}
我認為您只需將http://php.net/manual/fr/function.preg-match-all.php與正則表達式一起使用preg_match_all
$url = "http://www.test.com";
$pageContent = file_get_contents($url);
preg_match_all("#<title>(.*)<\/title>#sU",$pageContent, $matches);
if(isset($matches[0][1]) && $matches[0][1] == "Not Found")
$stepC = "NA";
} else{
$stepC = "ok";
}
echo $stepC;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.