Grow your CSS skills. Land your dream job.

Article title name as URL?

  • # April 17, 2013 at 2:34 am

    I am working on a simple CMS now, i have made post-new-page form, if i click “submit” button, the content will be saved into the database, by the same time i want the PHP script automatically create new folder in my root folder (i’m not sure whether it’s correct to create inside my root folder?)

    This is [the example](http://www.mactricksandtips.com/2013/03/speed-up-your-mac-by-solving-disk-errors-and-problems.html “example”).

    As you can see, the article’s URL (http://www.mactricksandtips.com/2013/03/**speed-up-your-mac-by-solving-disk-errors-and-problems**.html) equals to the article’s title (Speed Up Your Mac By Solving Disk Errors And Problems).

    How do i achieve this? Thanks in advanced.

    # April 17, 2013 at 3:02 am

    You can do this manually with PHP. This is called a slug.

    Basically, all you have to do is switch it to lower case, remove special chars and replace spaces by dashes. :)

    [Here](http://stackoverflow.com/questions/2955251/php-function-to-make-slug-url-string) is something that should help you.

    # April 17, 2013 at 6:01 am

    There is a great script on github: [BaconStringUtilsSlugifier](https://github.com/Bacon/BaconStringUtils) (you don’t need to use Zend to use the classes in `/src`.

    It does not only convert chars like `ö` to `o` but also `北亰` to `Bei Jing`, according to the readme (slugified that would be `bei-jing`)… You never know, right? ;)

    You then need to redirect requests to a common landing page (probably just `/index.php`, using .htaccess), read out the slug and query that page from a database (in which you have an indexed ‘unique, which is an index’ column with the slug to make queries fast).

    The `html` extension in your example doesn’t mean there is an actual html file.

    # April 17, 2013 at 6:05 am

    search in developphp.com , they got what you want.

    # April 17, 2013 at 6:30 am

    thank you for all the answers guys!

    digesting the explanation…..
    reading all the links……:)

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".