Link to home
Start Free TrialLog in
Avatar of dnotestine
dnotestine

asked on

How to get a Web POST variable into an array using PHP

Using PHP 4.3.2 I'm wanting to validate email addresses that are entered into a form. There may be one or more adrresses but multiples will be separated by commas ','.
i.e - dbn@acme.com,sam@acme.com
The following code does not work. Any ideas?
Also how to trim spaces out of the entry in case of:
i.e - dbn@acme.com, sam@acme.com

$emails = array($_POST['EmailRecipients']);
for ($i = 0; $i < count($emails); $i++) {
      if (!eregi ("^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$", $emails[i])) {
            ReportAdminError("Email is incorrect - $emails[i]",'Error','report_template');
            exit;
      }
}

Thanks in advance,
David

ASKER CERTIFIED SOLUTION
Avatar of LordOfPorts
LordOfPorts
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of David Beveridge
David Beveridge
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
MrEne, yours works along the same line as mine but doesn't remove the whitespace as requested.
to remove spaces. hope that works.
$emails = explode ( ',' , $_POST['EmailRecipients'] );
$emails = str_replace(" ", "", $emails );

Open in new window

Avatar of dnotestine
dnotestine

ASKER

Everyone was so fast it was hard to distribute the points. Sorry if I upset anyone with the point spread.