Welcome Guest, Not a member yet? Register   Sign In
Trying to make a url generator from a title
#4

First of all we need to strip all special characters and punctuation away. 
This is easily accomplished with something like:

function toAscii($str) {
$clean = preg_replace("/[^a-zA-Z0-9/_|+ -]/", '', $str);
$clean = strtolower(trim($clean, '-'));
$clean = preg_replace("/[/_|+ -]+/", '-', $clean);

return $clean;
}

Second option
setlocale(LC_ALL, 'en_US.UTF8');
function toAscii($str) {
$clean = iconv('UTF-8', 'ASCII//TRANSLIT', $str);
$clean = preg_replace("/[^a-zA-Z0-9/_| -]/", '', $clean);
$clean = strtolower(trim($clean, '-'));
$clean = preg_replace("/[/_| -]+/", '-', $clean);

return $clean;
}
Reply


Messages In This Thread
RE: Trying to make a url generator from a title - by XtreemDeveloper - 12-23-2017, 10:09 AM



Theme © iAndrew 2016 - Forum software by © MyBB