pietbez Posted September 9, 2008 Share Posted September 9, 2008 i have a code that validates links being posted by users. one problem. it wont alow me to post links with "-" in the url. like, www.music-zone.com it gives this error: Only alphanumeric characters allowed in domain names i think it is in this code please help function parseLink($link){ $err=""; if(substr($link, 0, 7) == "http://") { $rest = substr($link, 7); $proto = "http://"; } elseif(substr($link, 0, 6) == "ftp://") { $rest = substr($link, 6); $proto = "ftp://"; } else { $err .= "Unknown protocolol. Supported protocol are http:// and ftp://</br >"; } $link_part = explode("/", $rest, 2); if(strpos($link_part[0], ".")===false){ $err .= "Unknown domain. It's necessary to type domain names in standard way (ex. google.com, sourceforge.org)<br />"; } else { $subdomains = explode(".", $link_part[0]); $csd = count($subdomains); for($i=0; $i<$csd; $i++){ if(!ctype_alnum($subdomains[$i])){ $err .= "Only alphanumeric characters allowed in domain names<br />"; break; } } } Link to comment https://forums.phpfreaks.com/topic/123499-url-link-code/ Share on other sites More sharing options...
BlueSkyIS Posted September 9, 2008 Share Posted September 9, 2008 instead of if(!ctype_alnum($subdomains[$i])){ try this: if(!reg_match('/^[a-z0-9\-]+$/iD',$subdomains[$i])){ untested... Link to comment https://forums.phpfreaks.com/topic/123499-url-link-code/#findComment-637813 Share on other sites More sharing options...
pietbez Posted January 25, 2009 Author Share Posted January 25, 2009 i tried this, but no luck. still getting the same results. any other ideas? Link to comment https://forums.phpfreaks.com/topic/123499-url-link-code/#findComment-745840 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.