- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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!
Advertisements