Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP validate URI

Tags:

php

I want to validate a URI (not URL only) in PHP, though couldn't find any way to do this.

PHP does have parse_url() but it is not for URIs, it would be helpful to find a proper way to validate URI structures such as the following:

content://com.example.provider/articles/?optional=queries
like image 587
Amitoj Avatar asked Oct 22 '25 07:10

Amitoj


1 Answers

To validate URIs, you can use the FILTER_VALIDATE_URL filter with the filter_var() function in PHP.

$uri = "content://com.example.provider/articles/?optional=queries"

if (filter_var($uri, FILTER_VALIDATE_URL)) {
    // Valid URI, do something here.
}
like image 67
Skully Avatar answered Oct 24 '25 22:10

Skully