Hi everyone, I'm looking for an easy way to check if a string is equal to a URL:
http://youtu.be/WWQZ046NeUA
To convert it to the correct YouTube URL, follow these steps:
http://www.youtube.com/watch?v=WWQZ046NeUA
If you don't leave it alone, what is the easiest way to do this in php?
You can use this call preg_replace:
preg_replace
$u = 'http://youtu.be/WWQZ046NeUA'; $r = preg_replace('~^https?://youtu\.be/([a-z\d]+)$~i', 'http://www.youtube.com/watch?v=$1', $u);
str_replace must work miracles.
str_replace
$url = ''; //url you're checking $ytshorturl = 'youtu.be/'; $ytlongurl = 'www.youtube.com/watch?v='; if (strpos($url,$yturl) !== false) { $url = str_replace($ytshorturl, $ytlongurl, $url); }
: http://hasin.me/2009/05/05/expanding-short-urls-to-original-urls-using-php-and-curl/ : : http://www.php.net/manual/en/curl.installation.php