Wednesday 15 July 2015

http - Validate a URL PHP -


I have worked on a project and in this project I need to check the user input valid URL

I created a preg_match for all possible letters used at a URL However, I am trying to show an error if http: // // is not in front of HTTPS: // URL

Here I have what I have

  if (preg_match ('/ [^ 0-9a-zA-Z. \ - \ / :: & amp; = # % _] / ', $ Url) | substr ($ Url, 0, 7)! = "Http: //" || subst R ($ url, 0, 8)! = "Https: //") {  

But this is not working, I'm not sure I'm here What's wrong, I hope I can get some help!

If the statement returns true or false, then

  if (preg_match ('/ [^ 0- 9a-zA-Z. \ - \ / :: & amp; = $$) = subdomain ($ url, 0, 8)! Resonant "true"; } And {echo "false"; }   

I just need to see if the URL has entered a valid URL or not. I do not have to confirm it. I just have to check whether it has http: // or HTTPS: // and has valid URL characters. Instead of a regex, you can simplify things yourself and use the URL filtering:

P >

  if (filter_var ($ url, FILTER_VALIDATE_URL)) {...    

No comments:

Post a Comment