Hi all
I am having a small problem in my code. This piece of code get the site html data in an array. its working fine but when the url gets wrong I mean if changed the its start loading an infinite loop of errors.
Please let me know what will be the solution if I teminate the script when error found in url etc.
$urlmy="http://127.0.0.1/mypage.hml";
preg_match("/^(https?:\/\/)?([^\/]*)(.*)/i", "$myurl", $mymatches);
$mydomain = "http://" . $mymatches[2];
$mypage = $mymatches[3];
$getopen = fopen($mydomain.$mypage, "rb");
$code = "";
while(!feof($getopen)){
$mycode .= fread($getopen, 4096);
}
fclose($getopen);
The looping problem came when its try to open the url and not found ($getopen = fopen($mydomain.$mypage, "rb")😉 and unable to start the while loop. for example if I write mypageddddddd.hml instead of mypage.hml and (mypageddddddd.hml) is not availabl at the above mentioned url.
Below is the erro that i am getting if I put the wrong html url.
Warning: fopen(http://127.0.0.1/mypage.hml): failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in c:\apache\www\mypage.hml on line 7
Warning: feof(): supplied argument is not a valid stream resource in c:\apache\www\mypage.hml on line 9
Warning: fread(): supplied argument is not a valid stream resource in c:\apache\www\mypage.hml on line 10