Getting input and putting it into an array

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
RichGags
Forum Newbie
Posts: 9
Joined: Tue Jan 04, 2005 8:13 pm

Getting input and putting it into an array

Post by RichGags »

Hi. I subscribe to a text messaging service. I am writing a php script to accept input from a field for a phone number. I would like to pass that to the next page and have it go into an array. So if I input the phone numbers separated by commas, it would send my messages one at a time.

Currently my input page looks like this...

Code: Select all

<form action="sendit.php" method="post" name="form1">
<input type="text" name="phone" value="" size="160">
<input type="submit" value="Submit" name="submit">
Then in sendit.php I have...

Code: Select all


  $people = array(
        "+19145551111",
    );
What would I need to do to grab the input which could look like...

Code: Select all

+19145551111,+19145551212,+19145551313,+19145551414
and make the $people array look like this...

Code: Select all

 $people = array(
        "+19145551111",
        "+19145551212",
        "+19145551313",
        "+19145551414",
    );

Right now I am hard-coding the numbers when I need to send out bulk messages but I would rather do it via a input form page. Thanks!
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Getting input and putting it into an array

Post by requinix »

explode

Remember to validate the input.
RichGags
Forum Newbie
Posts: 9
Joined: Tue Jan 04, 2005 8:13 pm

Re: Getting input and putting it into an array

Post by RichGags »

Perfect! Thanks so much.
User avatar
liljester
Forum Contributor
Posts: 400
Joined: Tue May 20, 2003 4:49 pm

Re: Getting input and putting it into an array

Post by liljester »

jeffreyappel's solution seems a little excessive.

you could just stop at:

Code: Select all

$people = explode(',', $_POST['phone']);
and as was suggested, you should loop through the array and do any validation required on its values.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Getting input and putting it into an array

Post by requinix »

liljester wrote:jeffreyappel's solution seems a little excessive.
You're too nice. I would have said "wasteful" or "pointless".
Post Reply