EdRash Posted March 19, 2009 Share Posted March 19, 2009 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). Quote Link to comment Share on other sites More sharing options...
Renlok Posted March 19, 2009 Share Posted March 19, 2009 change "," to "\n" or "<br>" Quote Link to comment Share on other sites More sharing options...
EdRash Posted March 19, 2009 Author Share Posted March 19, 2009 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 Quote Link to comment Share on other sites More sharing options...
pkSML Posted March 19, 2009 Share Posted March 19, 2009 Have you tried preg_replace? You are wanting the output to be a multi-line string, correct? Quote Link to comment Share on other sites More sharing options...
EdRash Posted March 19, 2009 Author Share Posted March 19, 2009 Output allredy multiple, i want that multiple email input was separated by line and/or paragraph. I can try preg_replace, but where to place it? Quote Link to comment Share on other sites More sharing options...
pkSML Posted March 19, 2009 Share Posted March 19, 2009 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 Quote Link to comment Share on other sites More sharing options...
pkSML Posted March 19, 2009 Share Posted March 19, 2009 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. Quote Link to comment Share on other sites More sharing options...
EdRash Posted March 19, 2009 Author Share Posted March 19, 2009 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.