Forum Moderators: coopster

Message Too Old, No Replies

Storing Multiple Emails in an Array

         

HoboTraveler

10:57 am on Oct 2, 2006 (gmt 0)

10+ Year Member



Hi All,

I have a text box into which I enter a single email on each line. I am working on a script that will extract the email from each line.

I've been unable to figure out how to store the extracted emails into a session array so that the array can be printed out or stored into the DB in the subsequent pages.

Here is the code that extracts the emails. The storing in an array does not work..

Help would be appreciated..
TIA

<?php
$_SESSION['n_email'] = $_POST['emails'];

$_SESSION['n_email'] = explode("\n", $_SESSION['n_email']);

foreach($_SESSION['n_email'] as $v)
{
// call function to remove null or empty lines
$v = removeEmptyLines($v);

//skip blank lines
if(substr($v, 0, 1) == "")
{
continue;
}

//get the email
$email = explode("\n", $v);

// Storing this in an array does NOT work
$_SESSION['n_email'] = array($email[0]);

}

// This prints only one email
Echo "($_SESSION[n_email])";
?>

eelixduppy

12:11 pm on Oct 2, 2006 (gmt 0)



Try something like this to see what you get:

$email = $_POST['emails'];
$email = explode("\n\r", $email);
echo '<pre>';
print_r($email);
echo '</pre>';

Good luck!

HoboTraveler

2:13 pm on Oct 2, 2006 (gmt 0)

10+ Year Member



Perfect! Thank-You

Btw, I'm not sure if the \r is important. I removed the \r because all the emails were being displayed as a continuous string..

eelixduppy

3:13 pm on Oct 2, 2006 (gmt 0)



Actually, I just had it backwards...oops

$email = explode("\r\n", $email);

This thread [webmasterworld.com] may also be of interest to you.

Sorry about that ;)