note 16887 deleted from function.fopen by jimw

From: Date: Sat, 08 Dec 2001 23:27:35 +0000
Subject: note 16887 deleted from function.fopen by jimw
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-22333@lists.php.net to get a copy of this message
I was looking for a nice way of testing if a url is valid (ie. no '404 file not found' error returned) here's my actual version: function checkurl($url) { if ( $url ){ // if url exists urlencode($url); // transforms special characters in url $file = @fopen("$url", "r"); // @ suppresses error printing output if (!$file) $file = @fopen("$url/","r"); // add a trailing / if the url doesn't work if ( $file ){ // if file exists $isValid = true; // then it's valid } else { $isValid = false; } @fclose($file); } else { $isValid = false; } return $isValid; }

« previous php.notes (#22333) next »