Take a string such as:
In C#: How do I add \"Quotes\" around string in a comma delimited list of strings?
and convert it to:
Here's a solution for php:
function make_uri($input, $max_length) {
if (function_exists('iconv')) {
$input = @iconv('UTF-8', 'ASCII//TRANSLIT', $input);
}
$lower = strtolower($input);
$without_special = preg_replace_all('/[^a-z0-9 ]/', '', $input);
$tokens = preg_split('/ +/', $without_special);
$result = '';
for ($tokens as $token) {
if (strlen($result.'-'.$token) > $max_length+1) {
break;
}
$result .= '-'.$token;
}
return substr($result, 1);
}
usage:
echo make_uri('In C#: How do I add "Quotes" around string in a ...', 500);
Unless you need the uris to be typable, they don't need to be small. But you should specify a maximum so that the urls work well with proxies etc.