Snippets v2

Languages
My Snippets

Generate URL Safe Page Name Login or Register to Bookmark this snippet

Description PHP

This function trims, converts spaces to dashes, converts &'s to 'and' and removes commas. It was designed to convert page titles to url-safe names for rewrite rules, thus helping search engines.

The Code Download
  1. function GenerateUrlSafe($text) {
  2.     $text = convert_smart_quotes(strtolower($text));
  3.     $text = str_replace(" ","-",trim(stripslashes($text)));
  4.     $text = str_replace(",","",$text);
  5.     $text = str_replace("'","",$text);
  6.     $text = str_replace('"','',$text);
  7.     $text = str_replace("#","_",$text);
  8.     $text = str_replace("!","",$text);
  9.     $text = str_replace("?","",$text);
  10.     $text = str_replace("&","and",$text);
  11.     $text = str_replace("/","",$text);
  12.     $text = str_replace("\","",$text);
  13.    $text = str_replace(":","",$text);
  14.    $text = str_replace(";","",$text);
  15.    $text = str_replace("<","",$text);
  16.    $text = str_replace(">","",$text);
  17.    $text = str_replace("@","",$text);
  18.    $text = str_replace("*","",$text);
  19.    $text = str_replace("---","-",$text);
  20.    $text = str_replace("--","-",$text);
  21.    return $text;
  22. }
Credits Contact JC

Added by JC on 12th November, 2007

Comments

There are no comments about this snippet.

Post Comment HTML is allowed

You must be registered and logged in to post a comment.

Login here to post a comment