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

WBOY
Release: 2023-09-14 10:38:01
forward
979 people have browsed it

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!");
}
?>
Copy after login

Output

The following is the output result.

Valid URL!
Copy after login

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!");
}
?>
Copy after login

Output

This is the output.

Invalid URL!
Copy after login

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!

Related labels:
source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!