keevitaja Posted January 18, 2012 Share Posted January 18, 2012 how to validate url with preg_match so it wouldn't fail with local specials characters like: http://höme.com/whatever -- please note the o with dots. it is actually valid url Quote Link to comment https://forums.phpfreaks.com/topic/255302-how-to-validate-an-url/ Share on other sites More sharing options...
Psycho Posted January 18, 2012 Share Posted January 18, 2012 Try filter_var() with the FILTER_VALIDATE_URL flag. http://php.net/manual/en/function.filter-var.php EDIT: Never mind, the documentation states Validates value as URL (according to » http://www.faqs.org/rfcs/rfc2396), optionally with required components. Note that the function will only find ASCII URLs to be valid; internationalized domain names (containing non-ASCII characters) will fail. I guess you would have to create your own function to do this. I can think of two options. 1. You can either create a regex that has a complete white-list of characters AND checks the pattern. This would be very elaborate and would probably require multiple patters. 2. If the additional characters you want to allow are only accented characters have a process that replaces the accented characters with their non-accented counterparts (and saves to a temp var) and then use filter_var() on that temp value. filter_var() would then validate all the other formatting/ properties of the URL. If validation passes you can then use the original value before the replacements were made. Quote Link to comment https://forums.phpfreaks.com/topic/255302-how-to-validate-an-url/#findComment-1308957 Share on other sites More sharing options...
keevitaja Posted January 18, 2012 Author Share Posted January 18, 2012 i found a solution. i need to convert idn domain to ascii and then use filter_var found one converter from github: https://github.com/aluksidadi/IDN-Validator/blob/master/idna_convert.class.php Quote Link to comment https://forums.phpfreaks.com/topic/255302-how-to-validate-an-url/#findComment-1309050 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.