SF23103 Posted September 3, 2013 Share Posted September 3, 2013 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!! Link to comment https://forums.phpfreaks.com/topic/281829-cutting-firstnamelastname-out-of-firstlastdomaincom-in-a-mysql-result-to-php/ Share on other sites More sharing options...
kicken Posted September 3, 2013 Share Posted September 3, 2013 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 https://forums.phpfreaks.com/topic/281829-cutting-firstnamelastname-out-of-firstlastdomaincom-in-a-mysql-result-to-php/#findComment-1448052 Share on other sites More sharing options...
.josh Posted September 4, 2013 Share Posted September 4, 2013 $string = preg_replace('~\b([^.]+)\.([^@]+)@domain\.com~','$1 $2',$string); Link to comment https://forums.phpfreaks.com/topic/281829-cutting-firstnamelastname-out-of-firstlastdomaincom-in-a-mysql-result-to-php/#findComment-1448054 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.