![]() |
Best way to do se friendly urls?
Hey guys! I've got a little question.
I want to convert a title string into a link friendly string. Example: Site goes live! Needs to become: site-goes-live I know I can do string to lowercase and ' ', '-' replace, but what else can I add for weird symbols like é etc... Whats the easiest way to go round this? Thanks! |
I'd go with replacing the special characters with the normal characters. Perhaps using a map table would be the easiest way to accomplish this. I've done so for a romanian website, where I've replaced the diacritics with the associated alphabet letters.
|
Hmm, ok. Also, just found urlencode - does that do it for me automatically? Will give it a shot now myself :)
|
I used this for a project a while ago, worked pretty good:
PHP Code:
|
This is the code I would use to do it. However, although you can calculate the identifier on-the-fly, if you introduce any more characters into it then consider storing it in the database so you can be certain it can be reversed.
php Code:
|
1 Attachment(s)
The main idea (I think) would be that of keeping the URLs readable and syntactically correct.
I have attached the code, because the editor automatically converts html entities. It needs a little bit of refactoring, but it does the job. |
Mod_rewrite helps
|
Quote:
array('à' => 'a', 'é' => 'e' ... 'Ź' => 'Z'). There might be a lot of characters to consider but you'd only have to construct the translation table once. ^^ |
Hi Sam,
I came across this post a few minutes ago which may help - some useful comments on it as well about unicode character sets. Alan |
| All times are GMT. The time now is 12:43 PM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0