A Flash Developer Resource Site

Results 1 to 1 of 1

Thread: seo url friendly slug

  1. #1

    seo url friendly slug

    Can anyone point me towards a decent function for stripping out spaces and non-url-friendly characters from strings?

    This is the php version I found on bitrepository

    PHP Code:
    <?php
    function friendly_seo_string($string$separator '-')
    {
    $string trim($string);

    $string strtolower($string); // convert to lowercase text

    // Recommendation URL: http://www.webcheatsheet.com/php/regular_expressions.php

    // Only space, letters, numbers and underscore are allowed

    $string trim(ereg_replace("[^ A-Za-z0-9_]"" "$string));

    /*

    "t" (ASCII 9 (0x09)), a tab.
    "n" (ASCII 10 (0x0A)), a new line (line feed).
    "r" (ASCII 13 (0x0D)), a carriage return. 

    */

    $string ereg_replace("[ tnr]+""-"$string);

    $string str_replace(" "$separator$string);

    $string ereg_replace("[ -]+""-"$string);

    return 
    $string;
    }

    $str friendly_seo_string('Lorem Ipsum is simply dummy text.');

    // Outputs: lorem-ipsum-is-simply-dummy-text
    echo $str;
    ?>
    Last edited by friendlygiraffe; 12-15-2010 at 06:07 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center