Jump to content

First, middle, and last names


ejaboneta

Recommended Posts

I'm trying to set Apache to forward urls that would include a persons first name and last name. I would then use the first and last name to grab the content from a database

 

example:

http://example.com/profiles/michael-jackson

forwards to

http://example.com/profiles.php?first=michael&last=jackson

 

I've got it working using

profiles/([a-zA-Z]*)(-*)([a-zA-Z]*)

 

from this I take the first part as the first name and the third part as the last name since the second part is "-".

 

I'm having problems with middle names and names with hypens. Like if the name was Neil Patrick Harris, it would become Neil-Patrick-Harris and my code would take "Neil" as the first name and "Patrick" as the last name.

 

I thought since I'd be using php to grab the actual content, later I could just grab the last word and use that as the last name but then there'd be the problem with hyphenated names. "John Doe-Smith" would become "John-Doe-Smith" and only "Smith" would be taken as the last name.

 

 

 

Any help on how I can do this? I figured the solution would be a regex one since thats how I'm formatting all this.

Link to comment
Share on other sites

To overcome the problem with hyphenated names, you could use underscores in the URL instead of hyphens. So try this:

 

profiles/([a-zA-Z-]+)[a-zA-Z_-]*_([a-zA-Z-]+)

 

It should grab the first and last name, even when there's more than two names. It also allows hyphens in the names. Just remember to use underscores in the URL;

 

http://example.com/profiles/john_doe-smith_junior

Link to comment
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.