Jump to content

Recommended Posts

I'm working on a program that allows users to submit short articles. I'm going to mod_rewrite the URLs to make them friendly, and I need each article name to be unique so that access is simplified like this:

 

Article Name: How to Tie Your Shoe

Article URL:

www.mysite.com/articles/how_to_tie_your_shoe

 

I'll store the article name and the URL-friendly access name (how_to_tie_your_shoe) in a database.

 

Is there a function or mod out there that will do this for me? I feel like writing this would be reinventing the wheel. I just need to basically strip out special characters and replace spaces with _, but I'm wondering if I'm forgetting anything else that would prevent a URL from rendering properly.

 

The second part is making these unique: I need to check the database for pre-existing articles with the same submitted name and put together a unique identifier. I can easily append words onto the end of the article name based on some other criteria (like the article's author or when it was written), but again I have the feeling that this process has already been coded 1000 times by others. A google search, however, left me empty-handed. Any ideas?

Link to comment
https://forums.phpfreaks.com/topic/68870-making-an-article-name-url-friendly/
Share on other sites

You'll likely have to write it yourself if you haven't found anything searching google. There are plenty of code repository sites out there, but I have no idea if what you want is on one.

If you don't want to write it, hire someone.

Is there a function or mod out there that will do this for me? I feel like writing this would be reinventing the wheel. I just need to basically strip out special characters and replace spaces with _, but I'm wondering if I'm forgetting anything else that would prevent a URL from rendering properly.

 

<?php
$string = "How to Tie Your Shoe";

echo strtolower(str_replace(' ','_',preg_replace('/[^a-zA-Z0-9 ]/', '', $string)));
// output: how_to_tie_your_shoe
?>

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.