PHP FILTER_VALIDATE_URL Filter
Complete PHP Filter Reference
Definition and Usage
The FILTER_VALIDATE_URL filter validates value as an URL.
- Name: "validate_url"
- ID-number: 273
Possible flags:
- FILTER_FLAG_SCHEME_REQUIRED - Requires URL to be an RFC compliant URL
(like http://example)
- FILTER_FLAG_HOST_REQUIRED - Requires URL to include host name (like
http://www.example.com)
- FILTER_FLAG_PATH_REQUIRED - Requires URL to have a path after the domain
name (like www.example.com/example1/test2/)
- FILTER_FLAG_QUERY_REQUIRED - Requires URL to have a query string (like "example.php?name=Peter&age=37")
Example 1
<?php
$url = "http://www.example.com";
if(!filter_var($url, FILTER_VALIDATE_URL))
{
echo "URL is not valid";
}
else
{
echo "URL is valid";
}
?>
|
The output of the code will be:
Example 2
<?php
$url = "example.php?name=Peter&age=37";
if(!filter_var($url, FILTER_VALIDATE_URL,
FILTER_FLAG_QUERY_REQUIRED))
{
echo "URL is not valid";
}
else
{
echo "URL is valid";
}
?>
|
The output of the code will be:
Complete PHP Filter Reference
Click here to design a Stunning Flash Website for Free
Wix is a revolutionary web design tool that provides anyone with the possibility to create professional and beautiful websites for free.
With e-commerce features, search engine visibility and many more professional tools, Wix is the ultimate solution for creating a spectacular site while saving tons of money.
 |
W3Schools' Online Certification Program
The perfect solution for professionals who need to balance work, family, and career building.
More than 4000 certificates already issued!
|
The HTML Certificate documents your knowledge of HTML, XHTML, and CSS.
The JavaScript Certificate documents your knowledge of JavaScript and HTML DOM.
The XML Certificate documents your knowledge of XML, XML DOM and XSLT.
The ASP Certificate documents your knowledge of ASP, SQL, and ADO.
The PHP Certificate documents your knowledge of PHP and SQL (MySQL).
|