Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

274
Views
PHP validate URI

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
over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

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.
}

over 4 years ago · Santiago Trujillo Report

0

You can try the code below:

$url = "http://www.google.com";
if (!filter_var($url, FILTER_VALIDATE_URL) === false) {
    echo("$url is a valid URL");
} else {
    echo("$url is not a valid URL");
}
over 4 years ago · Santiago Trujillo Report

0

Needs to filter as well to remove illegal characters.

$url = "http://www.google.com"; 
// Remove all illegal characters from a url
$url = filter_var($url, FILTER_SANITIZE_URL);

// Validate url
if (filter_var($url, FILTER_VALIDATE_URL)) {
    echo("$url is a valid URL");
} else {
    echo("$url is not a valid URL");
} 

Here, the URL is required to have a query string to be valid:

$url = "https://www.w3schools.com";

if (filter_var($url, FILTER_VALIDATE_URL, FILTER_FLAG_QUERY_REQUIRED)) {
    echo("$url is a valid URL");
} else {
    echo("$url is not a valid URL");
}
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!