I am attempting to generate proper links from proper names...
For example: T & J Automotive is currently generated as /t-j-automotive
But, because I need to do a look up based on the name, I am unable to do said lookup when attempting to convert back to the name.
So... I've take care of ' by converting them to _, which works great for names like Mike's Shop (converts to mike_s-shop), but now I am faced with the &
Here is my current function:
// Fix the name for a SEO friendly URL
function FixNameForLink($str){
// Swap out Non "Letters" with a -
$text = preg_replace('/[^\\pL\d\']+/u', '-', $str);
// Trim out extra -'s
$text = trim($text, '-');
// Convert letters that we have left to the closest ASCII representation
$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
// Make text lowercase
$text = strtolower($text);
// ' has been valid until now... swap it for an _
$text = str_replace('\'', '_', $text);
// & has been valid until now... swap it for an .
$text = str_replace('&', '.', $text);
// Strip out anything we haven't been able to convert
$text = preg_replace('/[^-_\w]+/', '', $text);
return $text;
}
Note, the & replacement is not happenning. How can I make sure that any string passed to this function will have ' replace with _, and & replaced with .?