How To Check Given URL Is Valid Or Not PHP Function Example

  • 20-07-2022
  • 764
  • PHP
  • Haresh Chauhan

How to check whether the given URL is valid or not?; In this post, I will learn you how to check given given URL is a valid URL or not validate. This is very simple a PHP function will help us to check valid URLs.

Using PHP function filter_var(), This function will check and return boolean true if the URL is valid else it will return false. After Having This post you will easy to check URL using PHP function.

To check a valid URL in PHP, We need to pass two arguments in this function. In the first argument, we will pass the URL which we what to check and in the second argument need to pass type to check from the given string using this function.

How Do Check Whether The Email Address Valid Email Or Not In PHP Example

<?php

$url = "https://www.webappfix.com";

//First we will Remove all illegal characters from a url
$url = filter_var($url, FILTER_SANITIZE_URL);

// Validate url
if (!filter_var($url, FILTER_VALIDATE_URL) === false) {

  echo("$url is a valid URL"); // TRUE
} else {

  echo("$url is not a valid URL");
}

We always thanks to you for reading our blogs.


dharmesh-image

Dharmesh Chauhan

(Swapinfoway Founder)

Hello Sir, We are brothers origin from Gujarat India, Fullstack developers working together since 2016. We have lots of skills in web development in different technologies here I mention PHP, Laravel, Javascript, Vuejs, Ajax, API, Payment Gateway Integration, Database, HTML5, CSS3, and Server Administration. So you need our service Please Contact Us

haresh-image

Haresh Chauhan

(Co-Founder)


We Are Also Recommending You :