PHP sef url function

This is another PHP sef function, much better to use in case you want to get remove characters that are not a-z, 0-9, dash, underscore or space, then remove all leading and trailing spaces, change all dashes, underscores and spaces to dashes and return the modified string in lower case.


PHP search engine friendly url function

  1. function sef($string)
  2. {
  3. // remove all characters that aren’t a-z, 0-9, dash, underscore or space
  4. $not_acceptable_characters = '#[^-a-zA-Z0-9_ ]#';
  5. $string = preg_replace($not_acceptable_characters, '', $string);
  6. // remove all leading and trailing spaces
  7. $string = trim($string);
  8. // change all dashes, underscores and spaces to dashes
  9. $string = preg_replace('#[-_ ]+#', '-', $string);
  10. // return the modified string
  11. return strtolower($string);
  12. }

Related php tutorials:

  1. PHP SEF Clean url function

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark
tabs-top

Leave a Reply