slug for nice url

12Sep11
slug

slug

iata o functie foarte ok pentru a crea “Slug”:

    public function slug($str, $replace=array(), $delimiter=’-') {
setlocale(LC_ALL, ‘en_US.UTF8′);

if( !empty($replace) ) {
$str = str_replace((array)$replace, ‘ ‘, $str);
}

$clean = iconv(‘UTF-8′, ‘ASCII//TRANSLIT’, $str);
$clean = preg_replace(“/[^a-zA-Z0-9\/_|+ -]/”, ”, $clean);
$clean = strtolower(trim($clean, ‘-’));
$clean = preg_replace(“/[\/_|+ -]+/”, $delimiter, $clean);

return $clean;
}

Mie mi-a fost foarte utila , deoarece scap si de caracterele romanesti care imi faceau probleme.

Nu este facuta de mine, sursa este aici: http://cubiq.org/the-perfect-php-clean-url-generator



No Responses Yet to “slug for nice url”

  1. Lasă un comentariu

Lasă un răspuns

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Schimbă )

Twitter picture

You are commenting using your Twitter account. Log Out / Schimbă )

Facebook photo

You are commenting using your Facebook account. Log Out / Schimbă )

Connecting to %s


Follow

Get every new post delivered to your Inbox.