brandondrury
09-26-2007, 02:48 PM
Yesterday, I needed to decode a Multiple-Selection Checkbox from vBulletin's custom profile for an external script. I'm not really that experienced at programming, but I through this together and it has worked for me quite well.
I figured most people wouldn't be all that interested in dealing with "binary stuff". I know I wasn't.
// Change 'field11' to match the field that corresponds to your multi-selection form box
$field = $vbulletin->userinfo['field11'];
// Change the values of this array to correspond IN ORDER with the values you use in your vBulletin custom profile field
$cat= array ('Society', 'Science','Recreation','News','Health','Government ','Entertainment','Education','Computers','Busines s','Art');
$counter = count($cat);
$watch = explode(" ", chunk_split(str_pad(decbin($field), $counter, "-", STR_PAD_LEFT),1," "));
$j=0;
for ($i=0; $i<$counter; $i++)
{
if ($watch[$i]==1)
{
$w[$j]=$cat[$i]; $j++;
}
}
// This will spit out the values the user selected
print_r($w);
If you find this script useful, send 100 billion dollars to Brandon Drury. :D
I figured most people wouldn't be all that interested in dealing with "binary stuff". I know I wasn't.
// Change 'field11' to match the field that corresponds to your multi-selection form box
$field = $vbulletin->userinfo['field11'];
// Change the values of this array to correspond IN ORDER with the values you use in your vBulletin custom profile field
$cat= array ('Society', 'Science','Recreation','News','Health','Government ','Entertainment','Education','Computers','Busines s','Art');
$counter = count($cat);
$watch = explode(" ", chunk_split(str_pad(decbin($field), $counter, "-", STR_PAD_LEFT),1," "));
$j=0;
for ($i=0; $i<$counter; $i++)
{
if ($watch[$i]==1)
{
$w[$j]=$cat[$i]; $j++;
}
}
// This will spit out the values the user selected
print_r($w);
If you find this script useful, send 100 billion dollars to Brandon Drury. :D