Posted By

jprochazka on 10/02/10


Tagged

seo


Versions (?)

Make a "SEO Friendly URL" string.


 / Published in: PHP
 

The following function will return a SEO friendly URL using a supplied string.

  1. <?php
  2.  
  3. function seo($string){
  4. $string = preg_replace("`\[.*\]`U","",$string);
  5. $string = preg_replace('`&(amp;)?#?[a-z0-9]+;`i','-',$string);
  6. $string = preg_replace( "`&([a-z])(acute|uml|circ|grave|ring|cedil|slash|tilde|caron|lig|quot|rsquo);`i","\\1", $string );
  7. $string = preg_replace( array("`[^a-z0-9]`i","`[-]+`") , "-", $string);
  8. $string = htmlentities($string, ENT_COMPAT, 'utf-8');return strtolower(trim($string, '-'));
  9. }
  10.  
  11. ?>

Report this snippet  

You need to login to post a comment.