Format string

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
JimiH
Forum Commoner
Posts: 92
Joined: Thu Jun 15, 2006 6:10 am

Format string

Post by JimiH »

Hello

I have a variable $ENGINEER which contains a string

Example - SMITH BILL

I would like to format this string into the following

bill.smith@somewhere.com

Hope someone can help

Geoff
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

Code: Select all

$ENGINEER = "SMITH BILL";

$nameParts = explode(' ', strtolower($ENGINEER));

$email = $nameParts[1].'.'.$nameParts[0].'@somewhere.com';
JimiH
Forum Commoner
Posts: 92
Joined: Thu Jun 15, 2006 6:10 am

Post by JimiH »

Thanks Jaybird

That worked :D

The reason I had to change to the full email address is that the mail() function in
PHP didn't reconise "SMITH BOB" as a valid email address, however we use exchange
so "SMITH BOB" is fine in Outlook as it looks up the full email in the Global address book.

I'm nearly at the end of the project and assumed incorrectly that producing the names in the
"SMITH BOB" format and trying to use them in the mail() function would work.

I'm left with two varables

$SALESMAN

$ENGINEER

And an Aaray

$Project_members

Which all have the names in the "SMITH BOB" format which I need to convert into the full email address.

Is there anyway round this?

I suppose I could add an email fieild to the tables in the DB.

Thanks

Geoff
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

JayBird wrote:

Code: Select all

$ENGINEER = "SMITH BILL";

$nameParts = explode(' ', strtolower($ENGINEER));

$email = $nameParts[1].'.'.$nameParts[0].'@somewhere.com';

Code: Select all

$email = str_replace(' ', '.', strtolower($ENGINEER)).'@somewhere.com';
:wink:

Which all have the names in the "SMITH BOB" format which I need to convert into the full email address.
I am not sure what you are asking anymore..
I suppose I could add an email field to the tables in the DB.
This is ideal, yes.
JimiH
Forum Commoner
Posts: 92
Joined: Thu Jun 15, 2006 6:10 am

Post by JimiH »

I am not sure what you are asking anymore..
Hi

I know I'm confusing myself!!

Basicly I have a bunch of strings and one array with names in them, these are in the format "LAST NAME, FIRSTNAME" When I try to use the strings with the mail() function it gets rejected, it wants the full email address

firstname.lastname@somewhere.com

So either I add a email field or I convert the strings into full email addys.

Just as a quick question

What if there where more names in the string upto 8 maybe?

Example

$ENGINEER = SMITH BOB JONES TOM HENDRIX JIMI

Thanks

Geoff
Post Reply