Jump to content

url link code


pietbez

Recommended Posts

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
Share on other sites

  • 4 months later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.