How can I write a function to check whether the provided URLs is youtube or vimeo?
For instance, I have this two URLs that I store in a database as strings,
You can use preg_match()
:
$u1="http://vimeo.com/24456787";
$u2="http://www.youtube.com/watch?v=rj18UQjPpGA&feature=player_embedded";
if(preg_match('/http:\/\/(www\.)*vimeo\.com\/.*/',$u1)){
// do vimeo stuff
echo "Vimeo URL found!\n";
}
if(preg_match('/http:\/\/(www\.)*youtube\.com\/.*/',$u2)){
// do youtube stuff
echo "YouTube URL found!\n";
}