Jump to content

Recommended Posts

When a user clicks on a topic they are transfered to its post, which is retrieved by the name of the topic as given by the url value. up to now i have just used urlencode. But its trickier when a user adds slashes and dots into the mix. for example the title of the post is testing/testing. The url will go to www.asimpleforum.co.uk/t/testing/testing. How would i get around this since url encode doesnt do the job? I could replace slashes and dots with their own unique symbol but that produces the problem when someone uses one of those symbols that i use to replace in their topic title. I know one site in particular that replaces all dots and slashes with a hyphen (-), but how would you know what to turn the hyphen into when you query the database for that topic? Anyone have any ideas?

Link to comment
https://forums.phpfreaks.com/topic/247412-custom-url-encoding/
Share on other sites

There's a few ways of doing it.

 

1) Include an ID within the URL, making the post title redundant beyond SEO purposes. This would be best performance wise and you never have to worry about collisions.

2) As you query the database, you can pass the title column's value through an identical string manipulation process for comparison. Least preferable for performance, and dealing with collisions would be more complex (how many posts on here are created with "HELP!" or something?)

3) Or lastly, and the most clean way in terms of SEO, would be to store the post title within the database and look-up based on that. You could add a unique index to improve performance, and deal with collisions as you insert the row.

 

Edit

 

Just to be clear, this how you would solve the issues if you convert the slash to a hyphen - which I definitely recommend.

Link to comment
https://forums.phpfreaks.com/topic/247412-custom-url-encoding/#findComment-1270587
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.