Hi,
This function takes a regular phrase and formats it into a seo friendly string which can be part of an URL.
<?php function friendly_seo_string($string, $separator = '-') { $string = trim($string); $string = strtolower($string); // convert to lowercase text // Recommendation URL: http://www.webcheatsheet.com/php/regular_expressions.php // Only space, letters, numbers and underscore are allowed $string = trim(ereg_replace("[^ A-Za-z0-9_]", " ", $string)); /* "t" (ASCII 9 (0x09)), a tab. "n" (ASCII 10 (0x0A)), a new line (line feed). "r" (ASCII 13 (0x0D)), a carriage return. */ $string = ereg_replace("[ tnr]+", "-", $string); $string = str_replace(" ", $separator, $string); $string = ereg_replace("[ -]+", "-", $string); return $string; } $str = friendly_seo_string('Lorem Ipsum is simply dummy text.'); // Outputs: lorem-ipsum-is-simply-dummy-text echo $str; ?>
This string can be added to a friendly URL like this:
http://www.yourdomain.com/info/lorem-ipsum-is-simply-dummy-text.html
Recommendation URLs:
http://www.webcheatsheet.com/php/regular_expressions.php
http://www.php.net/manual/function.ereg-replace.php