PHP get youtube,vimeo video url from string and check if exist and play

When you are working with php, probably your page includes youtube or vimeo video url in the description.Check that youtube/vimeo video url is valid and that video is exist, then it must be play in the page.So now I’m going to describes how to get only that video url from the description, check that video is exist and how to to play it.

Think this is my description with including video url.

Now I want to get that video url.

PHP parse_url is parse the url and return its components like http,site url,query strings…etc.

Now get the video ID from string

Always video ID length is 11 characters for youtube video.
The individual characters come from a set of 64 possibilities (A-Za-z0-9_-).
64^11 is somewhat more than 2^64. (10 characters would not be enough.) So basically each youtube ID is actually a 64bit number. And I quite doubt they will ever run out of those.

Now Create the player for YOUTUBE VIDEO

Create the player for VIMEO VIDEO

Put this all together.

Download Source(1.43 KB)

Published by

Sumith Harshan

Sumith Harshan is the Web Engineer Specializes in Java Script, JQuery, HTML4/5, CSS2/3, PHP, CodeIgniter, CakePHP, J2SE, J2EE, XML, Hacking & Security, Mobile Interface Developing, Magento, Wordpress, Joomla, Drupal,PHPBB,Facebook App Developing and Open cart...etc.