/    Sign up×
Community /Pin to ProfileBookmark

Array and Foreach

User submits form that contains field called “inDomain” that contains “[email protected], [email][email protected][/email], [email][email protected][/email]

I want to do a loop that checks the submitted email address (which I can do in Perl, but PHP is just different enough that I need some help.)

Here is what is in my php file:

$Email = $_GET[“inDomain”];

$ckEmail = array(split(/,/,$Email));

foreach ($ckEmail as $vEmail) {
echo “something” or print $vEmail
}

I’m thinking I need to split the list based on commas as I would in Perl – is this correct? All of the examples I can find show you how to build an array first such as $bob = array(‘this’, ‘that’, ‘the other’)…

Here’s what the same thing looks like in Perl:

my $domain = param(‘domain’);
@ckEmail = split(/,/,$domain); #split emails based on commas
foreach $emaddr (@ckEmail) {
print something or print $emaddr or whatever
}

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@gtzpowerApr 18.2007 — try this:

[code=php]

$Email = $_GET["inDomain"];

$ckEmail = split(",",$Email);

foreach ($ckEmail as $vEmail) {
print $vEmail;
}
[/code]
Copy linkTweet thisAlerts:
@Suhas_DhokeApr 18.2007 — You can also use the function [B][COLOR="Blue"]explode()[/COLOR][/B] instead of [B][COLOR="Blue"]split()[/COLOR][/B].

And one more function you can use, i.e. [B][COLOR="Blue"]trim()[/COLOR][/B], to remove the spaces from the next email ids.

foreach ($ckEmail as $vEmail) {

print_r(trim($vEmail));

}
Copy linkTweet thisAlerts:
@WattsauthorApr 18.2007 — Thanks a million.

Keeping JavaScript, PHP and Perl straight is like my trying to do something via telnet. I'll type "bye", "quit", "exit" before one of them finally works (and I can never remember which one it is).
×

Success!

Help @Watts spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...