note 29189 added to function.implode
| From: | jim at jamesdavis dot it | Date: | Wed, 05 Feb 2003 16:32:26 +0000 |
| Subject: | note 29189 added to function.implode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-43466@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>";
}
}
--
http://www.php.net/manual/en/function.implode.php
http://master.php.net/manage/user-notes.php?action=edit+29189
http://master.php.net/manage/user-notes.php?action=delete+29189
http://master.php.net/manage/user-notes.php?action=reject+29189