Monday 14 April 2014

Creating and understanding SEO-Friendly URL'S Part 2

First guys we will look how a slug url look like 

http://www.example.com/This-is-a-seo-friendly-url

This is a  demo and this is what we are looking to achieve

So lets's the hacking begin.......

First we will create  a function which will handle the preparation of a slug url

<?php
    function generate_slug($slug)
  {
echo $text = "TTutorial to    show you how to create a ----- safe slug url v`v`k``` generator";
        echo "<br/>";
 ///// first remove everyting  other than spaces,hypens,number,letters and make the string to lowercase 
        echo $remove_slug1 = preg_replace("/[^\-\s\pN\pL]+/u", " ", mb_strtolower($text,'UTF-8'));

   echo "<br/>";
    /////  remove duplicate hypens and spaces//////
   echo $remove_slug2 = preg_replace("/[\-\s]+/", "-", $remove_slug1);
   echo "<br/>";
   echo $remove_slug3  = trim($remove_slug2,"-");
}
?>


No comments:

Post a Comment

Thank your for your comment..your submitted coment will be live after admin approval