This simple function gives you an idea how to generate more seo friendly urls like the one used in webdevelopmentscripts.com

This function takes maximum of 80 characters and removes any non printable characters and special characters etc... Have a look here:

public function make_title($title){
        if(is_null($title))
                return "";
            
        #remove multiple spaces between words
        $title=preg_replace('/\s\s+/',' ',$title);
            
        #removes non-printable characters, utf8 compatible
        $title=preg_replace('/[\x00-\x08\x0B\x0C\x0E-\x1F\x80-\xFF]/u', '', $title);

        $len = strlen($title);
        $prevdash = false;
        $sb=$c="";

        for($i=0;$i<$len;$i++){
        $c = $title[$i];
        if(($c>='a' && $c<='z') || ($c>='0' && $c<='9')){
            $sb.=$c;
            $prevdash = false;
        }
        elseif($c>='A' && $c<='Z'){
            // tricky way to convert to lowercase
            $sb.=strtolower($c);
            $prevdash = false;
        }
        elseif($c==' ' || $c==',' || $c=='.' || $c=='/' ||
            $c == '\\' || $c == '-' || $c == '_' || $c == '='){
            
            if(!$prevdash && strlen($sb)> 0){
                $sb.="-";
                $prevdash = true;
            }
        }
        
        if ($i == self::MAXLEN) break;
    }

        return($prevdash === true ? substr($sb,0,strlen($sb)-1) : $sb);

    }


Example:

make_tilte("drew wilson jquery autocomplete / autosuggest plugin");

Output:
drew-wilson-jquery-autocomplete-autosuggest-plugin
 


Comments (0)
Leave a Comment

loader Posting your comment...