Jump to content

cutting firstname.lastname out of [email protected] in a MySQL result to php


SF23103

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 [email protected].  In an instance of multiple email addresses in one row, it's listed as [email protected], [email protected], [email protected] (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!!

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.