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:

le="color: #000000"><?php $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 % 2 !=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 "<br>"; } $token = strtok(';:'); } echo "<br>"; echo"<select name='countries'>"; foreach (array_keys($country) as $j) { $country_id = $country[$j]['id']; $country_name = $country[$j]['name']; echo"<option value=".$country_id.">$country_name</option>n"; } echo"</select>";


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

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:


le="color: #000000"><?php $countries = 'a:2:{i:0;s:7:"abruzzo";i:1;s:10:"basilicata";}';


how i can extract countries?

thanks a lot

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

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


le="color: #000000"><?php $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:
<?php $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.'<br />'; } ?>


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 ;)

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

Who's Online

202 user(s) are online (156 user(s) are browsing Support Forums)


Members: 0


Guests: 202


more...

Donat-O-Meter

Stats
Goal: $15.00
Due Date: Jul 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $15.00
Make donations with PayPal!

Latest GitHub Commits