Its look like everything ok. It shows the result as well but it also shows Undefined offset: 1 error. Please help me with this.
$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";
}
Add some code like bellow:
$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";
}
}
I think you have to use preg_match_all with regex simply you code http://php.net/manual/fr/function.preg-match-all.php
$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;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.