[code=php]if (!isset($slug)) {
$slug = strtolower($title);
//replaces a word with spaces on either sides
$slug = preg_replace(‘/s(a)|(an)|(and)|(are)|(as)|(at)|(be)|(by)|(com)|(for)|(from)|(i)|(in)|(is)|(it)|(of)|(on)|(or)|(that)|(the)|(this)|(to)|(was)|(what)|(when)|(where)|(who)|(will)|(with)|(you)|(your)s/i’,’ ‘,$slug);
//the last word in the title
$slug = preg_replace(‘/s(a)|(an)|(and)|(are)|(as)|(at)|(be)|(by)|(com)|(for)|(from)|(i)|(in)|(is)|(it)|(of)|(on)|(or)|(that)|(the)|(this)|(to)|(was)|(what)|(when)|(where)|(who)|(will)|(with)|(you)|(your)$/i’,”,$slug);
//the first word in the title
$slug = preg_replace(‘/^(a)|(an)|(and)|(are)|(as)|(at)|(be)|(by)|(com)|(for)|(from)|(i)|(in)|(is)|(it)|(of)|(on)|(or)|(that)|(the)|(this)|(to)|(was)|(what)|(when)|(where)|(who)|(will)|(with)|(you)|(your)s/i’,”,$slug);
$slug = preg_replace(‘/s+/’,’-‘,$slug);
}
$slug = mysql_real_escape_string($slug);
The script supposedly removes all stopwords from a string, but I can’t get it to work. The string “the profile I like is fun” becomes “-pr-le-l-ke-s-fun” after passing through this script, when it’s suppose to become “profile-like-fun”. Help?