-1

im trying to get perm link witht his function:

    // Generates Permalink

function gen_permalink($title)
{
    $permalink=string_limit_words($title, 9);

if(!mb_check_encoding($permalink,"UTF-8"))
    {
        $permalink=preg_replace("/[^a-z0-9\s]/i", "", $permalink);
        $permalink=trim(preg_replace("/\s\s+/", " ", $permalink));
        $permalink=strtolower(str_replace(" ","-",$permalink));
    }
else
    {
        $permalink=trim($title);
        $permalink=str_replace(" ","-",$permalink);
    }
    $final = $permalink;
    $count = 1;
    while(already_exists($final))
    {
        $final = $permalink . "-" . $count;
        $count++; 
    }
    return $final;

but i cant menaged to do that..

Out put from

!its's SO funny! Blockquote

is

!its's-SO-funny!

Im trying to get

itss-so-funny

CEED
  • 1
  • 3
  • Why re-invent the wheel? There's a billion tiny libraries to do this. [Here](http://cubiq.org/the-perfect-php-clean-url-generator) is a version that's smaller than yours and work fine with UTF-8. Alternately, [this thread](http://stackoverflow.com/questions/2955251/php-function-to-make-slug-url-string) on SO contain a fine function as well. – h2ooooooo Feb 18 '14 at 20:01

1 Answers1

0

If you just want to get from

!its's-SO-funny! to itss-so-funny

You can just do something like this before returning:

$final = strtolower(preg_replace('/[^0-9a-zA-Z-]/','',$final));

It removes all characters except those which are alphanumeric or the symbol - and makes everything lowercase.

Anonymous
  • 11,748
  • 6
  • 35
  • 57