- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
FILTER_VALIDATE_URL constant in PHP
The FILTER_VALIDATE_URL constant validates a URL.
Flags
FILTER_FLAG_SCHEME_REQUIRED − URL must be RFC compliant.
FILTER_FLAG_HOST_REQUIRED − URL must include 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
The FILTER_VALIDATE_URL constant does not return anything.
Example
<?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.
Valid URL!
Let us see another example.
Example
<?php $url = "examplecom"; if (filter_var($url, FILTER_VALIDATE_URL)) { echo("Valid URL!"); } else { echo("Invalid URL!"); } ?>
Output
Here is the output.
Invalid URL!
- Related Articles
- FILTER_VALIDATE_BOOLEAN constant in PHP
- FILTER_VALIDATE_EMAIL constant in PHP
- FILTER_VALIDATE_FLOAT constant in PHP
- FILTER_VALIDATE_INT constant in PHP
- FILTER_VALIDATE_IP constant in PHP
- FILTER_VALIDATE_REGEXP constant in PHP
- FILTER_SANITIZE_EMAIL constant in PHP
- FILTER_SANITIZE_ENCODED constant in PHP
- FILTER_SANITIZE_MAGIC_QUOTES constant in PHP
- FILTER_SANITIZE_NUMBER_FLOAT constant in PHP
- FILTER_SANITIZE_NUMBER_INT constant in PHP
- FILTER_SANITIZE_SPECIAL_CHARS constant in PHP
- FILTER_SANITIZE_STRING constant in PHP
- FILTER_SANITIZE_STRIPPED constant in PHP
- FILTER_SANITIZE_URL constant in PHP

Advertisements