Jump to content

Number to Text?


jrws

Recommended Posts

Hey there,

 

That topic may be a little confusing to begin with so let me explain.

 

I know how to make this url-> www.example.com/articles?id=1 into www.example.com/articles/1

 

But how would I extract the topic so instead of a number it is the title? Would I need to change what is extracted from the database? Cause I extract articles based on their IDs, but I want the URL to reflect their titles. Is that possible?

 

I hope I have made sense, I don't really have any code to show, but if I can clarify on something, please ask and I will try.

 

 

Thanks,

 

James

Link to comment
https://forums.phpfreaks.com/topic/211568-number-to-text/
Share on other sites

No it is not possible. You cannot have the title in the URL and extract from the database based on the ID without also having the ID in the URL. One approach that some sites use is to have /id-title and use a rule such as ^(\d+)-[a-zA-Z0-9-]+/?$. If you echo out your URIs in this style you then have the ID you need to query your database. The other approach, which leaves a cleaner URL (as you don't need the ID at all) is to add a permalink/slug field to your database and query the database based on that instead of ID.

Link to comment
https://forums.phpfreaks.com/topic/211568-number-to-text/#findComment-1103060
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.