Home · Latest · Trends  /  PHP
4

Get YouTube Video ID and clean URL with PHP

rated 4 times [  4] [ 0]  / comments: 0 / hits: 1894  / 2 years ago, sun, mar 5, 2017, 13:51:18
Get YouTube Video ID and clean URL with PHP
<?php
//$url = 'https://www.youtube.com/watch?v=7JAqDMFmTYE&index=4&list=LL5ptMSzmMcoR0g0hISVnTWw';
//$url = 'https://www.youtube.com/watch?v=NU9JoFKlaZ0&list=PLo6aG-353Cqkrei8GU5adW9ZDbW_5Nl1X';
$url = 'https://www.youtube.com/watch?v=A1OqtIqzScI&index=6&list=PLo6aG-353Cqkrei8GU5adW9ZDbW_5Nl1X&gl=JP&hl=ja';
$youtube = preg_replace("#(^|[\n ])([\w]+?://)(www\.youtube)(\.[\w\.]+?/watch\?v=)([\w-]+)([&][\w=+&;%-_]*)*(^[\t <\n\r\]\[])*#is",'
<div>Real Url: \\2\\3\\4\\5\\6</div><hr />
<div>We don\'t need this part: \\6</div><hr />                      
<div>Clean Url: https://www.youtube.com/v/\\5</div><hr />
<div>Another Clean Url: https://www.youtube.com/watch?v=\\5</div><hr />
<div>Video ID: \\5</div><hr />
<div>Watch Video<br /><object><param name="movie" value="https://www.youtube.com/v/\\5"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed class="video" src="http://www.youtube.com/v/\\5" type="application/x-shockwave-flash" wmode="transparent" allowfullscreen="true"></embed></object></div>',
$url);
echo $youtube;
?>
More From » PHP
 

Comments

There are no comments for this Snippet yet
Only authorized users can post. Please sign in first, or register a free account
 
Share
Snippets
reCaptcha in smarty template file
2 years ago, mon, dec 5, 2016
reCAPTCHA v.2.0. Sample Form. You need to get API key for your site. https://www.google.com/recaptcha/admin#list
2 years ago, mon, jan 9, 2017
PHP stopforumspam integration example ans class
2 years ago, mon, jan 16, 2017
esoTalk forum script / esoTalk-BBCode plugin with color tag [plugin.php] [resources/bbcode.js]
2 years ago, sat, jan 21, 2017
Smarty section start loop: First result, second result, first and second result
2 years ago, fri, feb 10, 2017
PHP replace bad words function / form
2 years ago, fri, feb 10, 2017
Get a domain name IP address with PHP
2 years ago, tue, feb 28, 2017
HTML Purifier posting arrays example
2 years ago, thu, mar 16, 2017
Thunderbird userchrome.css example C://Users/<USER>/AppData/Roaming/Thunderbird/Profiles/<PROFILE>/chrome/userChrome.css
2 years ago, sun, apr 16, 2017
Posted
jimmy

jimmy

Member since Dec 15, 2016
Total Code Snippets: 15
Total Comments: 2
Location: n/a
Following
User not following anyone yet.