Re: Form With Array
| From: | Richard Lynch | Date: | Mon, 12 May 2003 07:42:03 +0000 |
| Subject: | Re: Form With Array | ||
| References: | 1 2 3 4 5 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-147267@lists.php.net to get a copy of this message | ||
Remon Redika wrote:
Hi EveryOne..
How to Print "text Form" In array..
I have Generatable "Textbox" which i have been manipulated it w/ jcript by InnerHTML.. blabla..
<input type="text" name="mytext">
I used php to print Textbox In array
$a = array($mytext);
$i = 0;
foreach($a as $v){
print "\$a[$i] => $v.\n";
$i++;
}
I want to get Output like this below
$a[0] => 1.
$a[1] => 2.
but i got the output just the last textbox which i have been added...
$a[0] => 2.
How To Do Array Here.., Help Please
I'm not really sure I understand the question...
If your form has several textboxes, the easiest way to get them in an array is to use:
<INPUT NAME=mytext[] >
<INPUT NAME=mytext[] >
<INPUT NAME=mytext[] >
.
.
.
This will automagically build an array when PHP processes the FORM elements.
You can even embed an ID inside each [] if you like:
<INPUT NAME=mytext[2] >
<INPUT NAME=mytext[5] >
<INPUT NAME=mytext[13] >
PHP will honor the keys you provide.
If you want to convert a single input string into an array...
Do you want it done character by character, or word by word or...?
word by word:
$array = explode(" ", $mytext);
character by character:
for ($i = 0; $i < strlen($mytext); $i++){
echo "$i ", $mytext[$i], "<BR>\n";
}
References:
http://php.net/explode
http://php.net/faq.php
http://php.net/strlen
http://php.net/char