Sat, January 23, 2021
 
https://devcodepro.comdevcodepro
Home · Latest · Trends  /  PHP
4

Get YouTube Video ID and clean URL with PHP

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;
?>
rated 4 times (4) (0)
comments: 1 / hits: 3916  / 4 years ago, sun, mar 5, 17, 01:51:18
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
Posted
jimmy
Member since Dec 15, 2016
Total Code Snippets: 16
Total Comments: 2
Location: n/a
jimmy snippets
4 years ago, mon, dec 5, 16, 1:47:20
comments: 1 / hits: 3926
PHP
4 years ago, mon, jan 9, 17, 2:50:09
comments: 1 / hits: 13444
PHP
4 years ago, mon, jan 16, 17, 2:18:41
comments: 1 / hits: 2396
PHP
4 years ago, sat, jan 21, 17, 5:41:42
comments: 0 / hits: 3009
PHP
4 years ago, fri, feb 10, 17, 12:02:07
comments: 1 / hits: 2519
PHP
4 years ago, fri, feb 10, 17, 12:15:34
comments: 0 / hits: 1839
PHP
4 years ago, tue, feb 28, 17, 9:40:06
comments: 0 / hits: 1773
PHP
4 years ago, thu, mar 16, 17, 5:51:45
comments: 1 / hits: 1791
PHP
4 years ago, sun, apr 16, 17, 3:44:59
comments: 1 / hits: 5998
CSS