How to Convert Short YouTube URL to Full URL in PHP

Convert Short YouTube URL to Full URL in PHP

Last Updated by Pooja Chikara

0 3405

To convert short YouTube URL to full URL, in PHP we can use preg_replace() function.

preg_replace(): It is an inbuilt function of PHP which used to search a particular content in a string and replace it with another content with the help of a regular expression.

For more details about preg_replace() function click here

Here is the code to convert a short YouTube URL to a full URL / Long Tail URL


<?php
$short_url = 'https://www.youtube.com/x7koOV63k4M';
$long_url= preg_replace('~^https?://www.youtube\.com/([a-z\d]+)$~i', 'http://www.youtube.com/watch?v=$1', $short_url);
echo $long_url;
?>

Output:

Result - How to Convert Short URL to Long Tail URL



Best WordPress Hosting


Share:

SSL for business, from $12.88


Leave a Reply


Comments
    Waiting for your comments

Coding Tag WhatsApp Chat
Coding Tag WhatsApp Chat