Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

278
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda