10-06-2008, 06:58 PM
|
#2 (permalink)
|
|
La Vida es Sueño
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
|
There are obviously people who are better than me with regular expressions, but here's my attempt, and it appears to work well:
PHP Code:
function is_youtube_link($szLink) { return (bool) preg_match('~http://(?:.+?\.)?youtube\.com.*~i', $szLink); }
$aLinks = array ( 'http://www.google.com/', 'http://uk.youtube.com/', 'http://www.yahoo.com/youtube.com', 'http://www.youtube.com', 'http://youtube.com' );
foreach ($aLinks as $szLink) { $szIsOrIsnt = is_youtube_link($szLink) ? '<font style="color: green">is</font>' : '<font style="color: red">is not</font>'; printf('<a href="%1$s">%1$s</a> <strong>%2$s</strong> a valid YouTube link.<br />', $szLink, $szIsOrIsnt); }
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
|
|
|