Jump to content

cutting firstname.lastname out of first.last@domain.com in a MySQL result to php


SF23103
Go to solution Solved by .josh,

Recommended Posts

I have a MySQL database in which each row has in it one or more email addresses.  The email addresses are unique to my organization and are firstname.lastname@domain.com.  In an instance of multiple email addresses in one row, it's listed as firstname.lastname@domain.com, firstname.lastname@domain.com, firstname.lastname@domain.com (seperated by commas).

 

My question is:

 

I am printing the data (along with other information) on a php page.  Instead of the whole email address, I would like to list the values as Firstname Lastname.  In an instance of more than one value, it would be Firstname Lastname, Firstname Lastname, Firstname Lastname (separated by commas).

 

Because the values I am looking for are firstname and lastname separated by a period and ending with an @ symbol, can I cut the rest of the email address out?  I think I figured out how to cut it, but then it won't display the second value if there is one.

 

What would be the easiest way to go about this?

 

Thanks!!

Link to comment
Share on other sites

explode the list by comma to separate each email out.

foreach over each email and then locate the position of the @ sign with strpos.

substr the email from position 0 to the position of the @ sign to extract the firstname.lastname

explode the firstname.lastname part on the period to separate them and use list to assign them to variables.

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.