ejaboneta Posted August 12, 2009 Share Posted August 12, 2009 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. Quote Link to comment Share on other sites More sharing options...
thebadbad Posted August 12, 2009 Share Posted August 12, 2009 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.