Hope I can be of any help again .. what you are doing seems rather
complicated... what if you have your checkboxes like:

<input type=checkbox name="checkbox[colors][1]" value="on">
<input type=checkbox name="checkbox[colors][4]" value="on">
<input type=checkbox name="checkbox[colors][6]" value="on">

and the recieving script just doing:

if (isset($_POST['colors']) && is_array($_POST['colors'])) $colors =
join(':', $_POST['colors']);

PHP will only register indexes in the $_POST['colors'] array for the boxes
that are checked, all your colors are in one array, so one simple join would
do the trick .. won't it? The if in front of it is just to prevent any
"undefined index" notices .. might you have E_ALL set as error level.

.. wait .. getting a message .. yeah, there's a better way

$colors = (isset($_POST['colors']) && is_array($_POST['colors'])) ? $colors
= join(':', $_POST['colors']) : '';

now your $colors variable will always be set with a string value.

Grtz,
Wouter

Ps. anybody knows when syntax highlighting is gonna be an option in MS
Outlook? Would be neat, wouldn't it?

-----Oorspronkelijk bericht-----
Van: Kris Yates [mailto:[EMAIL PROTECTED]
Verzonden: vrijdag 15 augustus 2003 23:53
Aan: [EMAIL PROTECTED]
Onderwerp: [PHP] Bug in Ereg?


Hi,

I have a form with checkboxes that POSTs to a PHP script.

What is posted [ from phpinfo() ]:

_POST["color-1"]        on
_POST["color-4"]        on
_POST["color-6"]        on


Parser:
    foreach($_POST as $ThisVar=>$ThisVal){
        if(ereg("color-", $ThisVar) AND $ThisVal=="on" OR $ThisVal==1){
            $newVarA=explode("-", $ThisVar);
            $colors.="$newVarA[1]:";
            }
        }

Expected Output:

$colors="1:4:6:";

Real Output:

$colors=":1:4:6:";

I can work with the output I am getting, however, I am curious why I am
not getting the "expected output".  Can anyone shed light on this?  I am
using PHP 4.3.2 compiled under a unix environment.  Is this a bug in
ereg or am I just not seeing something obvious in my foreach?

Thanks,

Kris



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to