Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,880 questions

51,806 answers

573 users

How to sanitize and validate an URL with filter in PHP

2 Answers

0 votes
/*
mixed filter_var ( mixed $variable [, int $filter = FILTER_DEFAULT [, mixed $options ]] )

// Check URL (according to: http://www.faqs.org/rfcs/rfc2396)
*/
   
$url = "http://www.collectivesolver.com";

// Remove illegal characters 
$url = filter_var($url, FILTER_SANITIZE_URL);

// Validate url
if (!filter_var($url, FILTER_VALIDATE_URL) === false) 
    echo("$url is valid URL");
else 
    echo("$url is not valid URL");

        
/*
run:
    
http://www.collectivesolver.com is valid URL 
  
*/

 



answered Dec 26, 2015 by avibootz
edited Dec 26, 2015 by avibootz
0 votes
/*
mixed filter_var ( mixed $variable [, int $filter = FILTER_DEFAULT [, mixed $options ]] )

// Check URL (according to: http://www.faqs.org/rfcs/rfc2396)
*/
   
$url = "http://www.collectivesolver.com";

// Remove illegal characters 
$url = filter_var($url, FILTER_SANITIZE_URL);

// Validate url
if (!filter_var($url, FILTER_VALIDATE_URL, FILTER_FLAG_QUERY_REQUIRED) === false) 
    echo("$url is valid URL");
else 
    echo("$url is not valid URL");

        
/*
run:
    
http://www.collectivesolver.com is not valid URL 
  
*/

 



answered Dec 26, 2015 by avibootz

Related questions

2 answers 278 views
2 answers 246 views
4 answers 300 views
3 answers 326 views
326 views asked Jun 18, 2016 by avibootz
2 answers 761 views
1 answer 241 views
1 answer 155 views
155 views asked Aug 3, 2018 by avibootz
...