PHP SEO url string filter


/ Published in: PHP
Save to your folder(s)

This function will transform any string to an seo url like string. It suports latin, french and german special characters.

Example: applying the function to "Exemplo de aplicação da função" returns "exemplo-de-aplicacao-da-funcao"


Copy this code and paste it in your HTML
  1. <?php
  2.  
  3. function seoUrl($str){
  4. /** by Jonatas Urias B Teixeira **/
  5. $a = array('/(à|á|â|ã|ä|å|æ)/','/(è|é|ê|ë)/','/(ì|í|î|ï)/','/(ð|ò|ó|ô|õ|ö|ø|œ)/','/(ù|ú|û|ü)/','/ç/','/þ/','/ñ/','/ß/','/(ý|ÿ)/','/(=|\+|\/|\\\|\.|\'|\_|\\n| |\(|\))/','/[^a-z0-9_ -]/s','/-{2,}/s');
  6. $b = array('a','e','i','o','u','c','d','n','ss','y','-','','-');
  7. return trim(preg_replace($a, $b, strtolower($str)),'-');
  8. }
  9.  
  10. ?>

URL: http://tinyphp.tumblr.com/post/3750074024/php-seo-url-string-filter

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.