21
mawi27
Re: Drop down menu with unserlize function ?
  • 2008/4/14 11:46

  • mawi27

  • Friend of XOOPS

  • Posts: 103

  • Since: 2006/1/1 1


Hi Stefano,

thanks for visiting my website

Try this code for your problem:

$countries 'a:2:{s:5:"milan";s:6:"Milano";s:6:"naples";s:6:"Napoli";}';

$token strtok($countries,';:');
$q=1;
while (
$token) {

    if (
substr($token,0,1) == '"') {
        echo 
$q," ",$token," ",substr($token,1,-1);

        if (
$q !=0)
        {
            echo 
" -> number is odd";
            
$country[$q]['id'] = substr($token,1,-1);
        }
            
        else
        {
            echo 
" -> number is even";
            
$country[$q-1]['name'] = substr($token,1,-1);
        }  
        
        
$q++;
        echo 
"
"
;
    }
    
$token strtok(';:');
    
}

echo 
"
"
;

echo
"";
foreach (
array_keys($country) as $j) {
 
$country_id $country[$j]['id'];
 
$country_name $country[$j]['name'];
 echo
".$country_id.">$country_namen";
}    
echo
"";


arrivederci,

Marco
--
Match Dart!
Darts Ranking, News, Videos, Forum and more

22
slyss
Re: Drop down menu with unserlize function ?
  • 2008/4/14 11:53

  • slyss

  • Quite a regular

  • Posts: 343

  • Since: 2006/1/26


it's perfect!

thanks a lot!

Verabschieden
[size=x-large]2008 Xoops Book[/size]

23
slyss
Re: Drop down menu with unserlize function ?
  • 2008/5/18 21:34

  • slyss

  • Quite a regular

  • Posts: 343

  • Since: 2006/1/26


hi marco


if i have this:


$countries 'a:2:{i:0;s:7:"abruzzo";i:1;s:10:"basilicata";}';


how i can extract countries?

thanks a lot
[size=x-large]2008 Xoops Book[/size]

24
trabis
Re: Drop down menu with unserlize function ?
  • 2008/5/18 21:56

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


$countries 'a:2:{i:0;s:7:"abruzzo";i:1;s:10:"basilicata";}';
$data unserialize($countries);
echo 
$data[0];//abruzzo
echo $data[1];//basilicata

25
trabis
Re: Drop down menu with unserlize function ?
  • 2008/5/18 22:11

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


You can test diferent outputs this way:
$countries 'a:2:{i:0;s:7:"abruzzo";i:1;s:10:"basilicata";}';
//$countries = 'a:2:{s:5:"milan";s:6:"Milano";s:6:"naples";s:6:"Napoli";}';
$data unserialize($countries);
foreach (
$data as $key=>$value){
    echo 
$key.' -> '.$value.'';
}

?>


As you see one uses keys and the other does not.

26
slyss
Re: Drop down menu with unserlize function ?
  • 2008/5/19 6:31

  • slyss

  • Quite a regular

  • Posts: 343

  • Since: 2006/1/26


many thanks ;)
[size=x-large]2008 Xoops Book[/size]

27
mawi27
Re: Drop down menu with unserlize function ?
  • 2008/5/19 14:37

  • mawi27

  • Friend of XOOPS

  • Posts: 103

  • Since: 2006/1/1 1


Hi slyss,
the unserialize() function explained by trabis is much better than parsing the string as i have worked out in your other posts! You should change your code so that you only use this function.

best regards,
Marco
--
Match Dart!
Darts Ranking, News, Videos, Forum and more

Login

Who's Online

423 user(s) are online (333 user(s) are browsing Support Forums)


Members: 0


Guests: 423


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits