Validating a link in php

From: Date: Thu, 01 Jan 1970 00:00:00 +0000
Subject: Validating a link in php
Groups: php.general 
Request: Send a blank email to php-general+get-247707@lists.php.net to get a copy of this message
Hi all, I'm hoping y'all can help me with a bit of a php code problem I'm having. What I'm trying to do is link to YouTube videos (more than one in a single webpage). However, because I'm worried about the videos going away and the links going bad, I'd like to use PHP to check if the link is good; if it's good, display the video link, else display a static image that I have on my servers. Where I'm having troubles is in the checking of whether the url is good. I think part of the problem is YouTube itself. I've tried file() and fsockopen(), but neither seem to work. Below is an example of the block of code I'm trying to write. <? error_reporting(E_ALL ^ E_NOTICE); if (the "http://www.youtube.com/v/JqO8ZevPJNk" url is valid) <-- ??? { echo " <object height=\"400\" width=\"475\">\n"; echo " <param name=\"movie\" value=\"http://www.youtube.com/v/JqO8ZevPJNk\">\n"; echo " <embed src=\"http://www.youtube.com/v/JqO8ZevPJNk\"\n"; echo " type=\"application/x-shockwave-flash\" height=\"400\" width=\"475\">\n"; echo " </object>\n"; } else { echo " <a href=\"10538overturevideo.jpg\"><img SRC=\"10538overturevideo.jpg\" height=\"130\"></a>\n"; } ?> Many thanks for any assistance you can provide. Robert Porter

« previous php.general (#247707) next »