Home  >  Article  >  Backend Development  >  In PHP, the FILTER_VALIDATE_URL constant represents the filter used to validate URLs

In PHP, the FILTER_VALIDATE_URL constant represents the filter used to validate URLs

WBOY
WBOYforward
2023-09-14 10:37:021012browse

In PHP, the FILTER_VALIDATE_URL constant represents the filter used to validate URLs

The FILTER_VALIDATE_URL constant is used to validate the URL.

Flags

  • FILTER_FLAG_SCHEME_REQUIRED − URL must comply with RFC standards.

  • FILTER_FLAG_HOST_REQUIRED − The URL must contain the host name.

  • FILTER_FLAG_PATH_REQUIRED −URL must have a path after the domain name.

  • FILTER_FLAG_QUERY_REQUIRED −URL must have a query string.

Return value

The FILTER_VALIDATE_URL constant does not return anything.

Example

Demonstration

<?php
$url = "https://www.example.com";
if (filter_var($url, FILTER_VALIDATE_URL)) {
   echo("Valid URL!");
} else {
   echo("Invalid URL!");
}
?>

Output

The following is the output result.

Valid URL!

Let’s look at an example.

Example

Real-time demonstration

<?php
$url = "examplecom";
if (filter_var($url, FILTER_VALIDATE_URL)) {
   echo("Valid URL!");
} else {
   echo("Invalid URL!");
}
?>

Output

This is the output.

Invalid URL!

The above is the detailed content of In PHP, the FILTER_VALIDATE_URL constant represents the filter used to validate URLs. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete