PHP: How to check whether the URL is Youtube's or vimeo's

Viewed 34369

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,

http://vimeo.com/24456787

http://www.youtube.com/watch?v=rj18UQjPpGA&feature=player_embedded

If the URL is youtube then I will rewrite the URL to,

http://www.youtube.com/embed/rj18UQjPpGA?rel=0&wmode=transparent

If the URL is vimeo then I will rewrite this URL to,

http://vimeo.com/moogaloop.swf?clip_id=24456787

Thanks.

8 Answers

You can try this

<?php
  if (strpos($videourl, 'youtube') > 0) {
    echo 'This is a youtube video';
  } 
?>
Related