Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

How to automatically create seo friendly php-slugs like wordpress for my blog?

Hi How can I automatically create seo friendly php-slugs like wordpress for my blog and Later on after creating them, how will I be able to fetch the data from the database?

1 Answer

Petros Sordinas
Petros Sordinas
16,181 Points

Hi Rohit,

I suppose your blog posts have title, therefore you can create a slug out of the title automatically. However, slugs must have url-friendly characters so you must pass the value to a 'slugify' (or whatever else you want to call it function). See this thread in stackoverflow for a function example (1st reply) http://stackoverflow.com/questions/2955251/php-function-to-make-slug-url-string

Once you have the slug, you will save it as a field on your posts table in your db. If your blog now retrieves posts by an id or some other key, you will have to modify your code to search for the slug.

Thank You. I got my answer.