Convert Short YouTube URL to Full URL in PHP

convert short youtube url to full url in php

0 1265

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.

$short_url = '';
$long_url= preg_replace('~^https?://\.com/([a-z\d]+)$~i', '$1', $short_url);
echo $long_url;



Leave a Reply

    Waiting for your comments