Jump to content

One per line function?


EdRash

Recommended Posts

Please Help!

 

I have invite function on my site, that allows send multiple invite emails separated by commas:

 

$invite_emails = implode(",", array_slice(explode(",", $invite_emails)

 

I want to change function so, that emails was separated by line (one email per line).

Link to comment
Share on other sites

It's dosn't work, if:

 

$invite_emails = implode("\n", array_slice(explode("\n", $invite_emails)

or

$invite_emails = implode("<br>", array_slice(explode("<br>", $invite_emails)

send only one email.

 

if:

$invite_emails = implode("\n"\n array_slice(explode("\n"\n $invite_emails)

or

$invite_emails = implode("<br>"<br> array_slice(explode("<br>"<br>

$invite_emails)

give syntax error

 

Link to comment
Share on other sites

Here are the arguments:

mixed preg_replace ( mixed pattern, mixed replacement, mixed subject [, int limit [, int &count]] )

 

So, here's how I'd do it.

<?php
$invite_emails = 'john@doe.com, jane@doe.com, testing@mydomain.com,me@me.net';
$search = array('@,\s@', '@,@');
$replace = array("\n", "\n");
$invite_emails = preg_replace($search, $replace, $invite_emails);
echo "<PRE>" . $invite_emails . "</PRE>";
?>

 

This script takes this:

john@doe.com, jane@doe.com, testing@mydomain.com,me@me.net

and makes it this:

john@doe.com
jane@doe.com
testing@mydomain.com
me@me.net

 

Link to comment
Share on other sites

Here are the arguments:

mixed preg_replace ( mixed pattern, mixed replacement, mixed subject [, int limit [, int &count]] )

 

So, here's how I'd do it.

<?php
$invite_emails = 'john@doe.com, jane@doe.com, testing@mydomain.com,me@me.net';
$search = array('@,\s@', '@,@');
$replace = array("\n", "\n");
$invite_emails = preg_replace($search, $replace, $invite_emails);
echo "<PRE>" . $invite_emails . "</PRE>";
?>

 

This script takes this:

john@doe.com, jane@doe.com, testing@mydomain.com,me@me.net

and makes it this:

john@doe.com
jane@doe.com
testing@mydomain.com
me@me.net

 

PS If you need more help, put an example of what $invite_emails looks like in [ code ] tags.

Link to comment
Share on other sites

It's not exacly what  I want.

 

The current code is:

// CHECK FOR NO INVITE EMAILS
if(trim($invite_emails) == "") { $is_error = 1073; }
// SEND INVITATION IF NO ERROR
if($is_error == 0) { 
$invite_emails = implode(",", array_slice(explode(",", $invite_emails), 0, 100));

 

I want that script take this and send as is:

john@doe.com
jane@doe.com
testing@mydomain.com
me@me.net

 

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.