Balderick Posted August 20, 2016 Share Posted August 20, 2016 I have a thing I dont get. I found this regex part to check for correct subdomains. function check_subdomain($data){ if (!empty($data)){ $data = preg_match("/^(?:[A-Za-z0-9][A-Za-z0-9\-]{0,61}[A-Za-z0-9]|[A-Za-z0-9])$/", $data); return($data); } else { } } echo check_subdomain($data); but the strange thing is that echo check_subdomain($data) outputs the input and adds a 0 when wrong and a 1 when correct. why is this done and how to avoid it? Link to comment Share on other sites More sharing options...
Ingolme Posted August 20, 2016 Share Posted August 20, 2016 That's not all of your code. I suspect you're printing out $data somewhere else. You have an unnecessary else statement, just remove that from your code. You can simplify your function to just this: function check_subdomain($data){ return preg_match("/^(?:[A-Za-z0-9][A-Za-z0-9\-]{0,61}[A-Za-z0-9]|[A-Za-z0-9])$/", $data); } Link to comment Share on other sites More sharing options...
Balderick Posted August 21, 2016 Author Share Posted August 21, 2016 Ok thanks for your help guys Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now