RE: [PHP] Bug in Ereg?

This is a discussion on RE: [PHP] Bug in Ereg? within the PHP General forums, part of the PHP Programming Forums category; ow .. this script won't work .. checkboxes like this: <input type=checkbox name="colors[1]" value="...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 08-16-2003
Wouter Van Vliet
 
Posts: n/a
Default RE: [PHP] Bug in Ereg?

ow .. this script won't work ..

checkboxes like this:
<input type=checkbox name="colors[1]" value="on">

or var calling like this:
$_POST['checkbox']['colors']

would do better ;) of course :D:D

-----Oorspronkelijk bericht-----
Van: Wouter van Vliet [mailto:wouter@esctoday.com]
Verzonden: zaterdag 16 augustus 2003 1:06
Aan: Kris Yates; php-general@lists.php.net
Onderwerp: RE: [php] Bug in Ereg?


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:kris@2binteractive.com]
Verzonden: vrijdag 15 augustus 2003 23:53
Aan: php-general@lists.php.net
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 With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 02:36 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0