note 29190 rejected from faq.html by nicos
| From: | nicos@php.net | Date: | Wed, 05 Feb 2003 20:05:35 +0000 |
| Subject: | note 29190 rejected from faq.html by nicos | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-43473@lists.php.net to get a copy of this message | ||
If you do this to pass an array through a form to another page
for ($n=0; $n<= count($choice) -1; $n++){
echo "<input type=\"hidden\" name=\"choice[]\"
value=$choice[$n]></input>";
}
and then you extract it and output it to a page with
for ($n=0; $n<= count($_POST['choice']) -1; $n++){
if ($_POST['choice'][$n] != "") {
$choice[$n] = slash_and_html($_POST['choice'][$n]);
echo $choice[$n]."<BR>";
}
}
[ slash_and_html returns stripslashes(htmlspecialchars($the_string,ENT_QUOTES)); ]
everything works fine as long as the array does not contain a number. If you put numbers in your
array strings such as:
1st choice
2nd choice
Choice 3
choice 4
3 choice
What you get out is this:
1st
2nd
Choice
choice
3
for some reason the string is truncated at or near the number. Maybe somebody might like to report
this as a bug, but maybe the bug is in the documentation which tells you to use this method when
there is a simple easier method. Use the array implode and explode functions which convert an array
into a string and vice versa and pass the array as a string.
Send with this:
$choice_imploded = implode("|", $choice);
echo "<input type=\"hidden\" name=\"choice_imploded\"
value=$choice_imploded></input>";
and receive and print with this
$choice = explode("|", $_POST['choice_imploded']);
for ($n=0; $n<= count($choice) -1; $n++){
if ($choice[$n] != "") {
$choice[$n] = slash_and_html($choice[$n]);
echo $choice[$n]."<BR>";
}
}
P.s. I carefully read this through before I sent it and then sent it to the implode function page by
mistake :(