Make a \"SEO Friendly URL\" string.


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

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


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.