05-09-2009, 04:46 AM
|
|
|
Confirmed User
Industry Role:
Join Date: Mar 2004
Location: Rock Hill, SC
Posts: 5,370
|
Quote:
Originally Posted by fris
remove it.
Code:
<?php
function cleanURL($string)
{
$url = str_replace("'", '', $string);
$url = str_replace('%20', ' ', $url);
$url = preg_replace('~[^\\pL0-9_]+~u', '-', $url); // substitutes anything but letters, numbers and '_' with separator
$url = trim($url, "-");
$url = iconv("utf-8", "us-ascii//TRANSLIT", $url);// you may opt for your own custom character map for encoding.
$url = strtolower($url);
$url = preg_replace('~[^-a-z0-9_]+~', '', $url); // keep only letters, numbers, '_' and separator
return $url;
}
// echo cleanURL("Shelly's%20Greatest%20Poem%20(2008)"); // shellys-greatest-poem-2008
?>
|
wtf is that mess?
Code:
<?php
function cleanURL($url, $seperator = '-') {
$url = ereg_replace("[^[:alnum:][:space:]]", "", $url); //remove all but numbers. letters and spaces
$url = str_replace(' ', ' ', $url ); //replace and double spaces with a single space
$url = strtolower(str_replace(' ', $seperator, $url)); //replace spaces with seperator
return $url
}
// echo cleanURL(urldecode("Shelly's%20Greatest%20Poem%20(2008)")); // shellys-greatest-poem-2008
// echo cleanURL("Shelly's Greatest Poem (2008)"); // shellys-greatest-poem-2008
?>
|
|
|