How to Validate YouTube Video URL Format in PHP using parse_url() function in Browser Full Project For Beginners

  • Post author:
  • Post category:PHP
  • Post comments:0 Comments

 

 

Welcome folks today in this blog post we will be validating youtube video url format in php using parse_url() function in browser using php 7 . All the full source code of the application is shown below.

 

 

 

Get Started

 

 

 

In order to get started you need to make an index.php file and copy paste the following code

 

 

 

index.php

 

 

 

<?php
   $yt_url = "https://www.youtube.com/watch?v=cCO2tPGa-dM";
   $url_parsed_arr = parse_url($yt_url);

   if ($url_parsed_arr['host'] == "www.youtube.com" && $url_parsed_arr['path'] == "/watch" && substr($url_parsed_arr['query'], 0, 2) == "v=" && substr($url_parsed_arr['query'], 2) != "") {
        echo "The URL is a valid YouTube link";
   } else {
       echo "Not a valid YouTube link";
   }

?>

 

Leave a Reply