Jump to content

Recommended Posts

Hi,

 

I have a form that accepts email addresses separated by ";", like this:

 

[email protected]; [email protected], [email protected]

 

I will use PHPMailer to send this emails, and I need to cut the "[email protected]; [email protected]; [email protected]", into this:

 

$mail1 = "[email protected]";
$mail2 = "[email protected]";
$mail2 = "[email protected]";

 

How can I solve this problem? Wich is the best solution?

 

 

Ps: Sorry my english.

 

Best Regards, André.

explode will explode the string at the semicolons, and put each item into an array.  Example:

 

$string = "[email protected]; [email protected]; [email protected]";
$email = explode(";",$string);

 

However, if there is also a space after the semicolon, each email is going to have a leading space.  If you are 100% sure that there will always be a space, you can include the space in the explode like so:

 

$email = explode("; ",$string);

 

If you are not 100% sure (as in, it may or may not have a space), you can either loop through the array and trim each element, or you can instead, use preg_split, making it optionally match the space, like so:

 

$email = preg_split('~;\s?~',$string);

 

Understand that all of these methods makes an array, so does not make like $email1, $email2, $email3, etc... it makes $email[0], $email[1], $email[2], etc...

 

 

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.