Page 1 of 1

Parsing issue

Posted: Mon Nov 15, 2010 1:35 am
by len_hulley
Hello there,

I am trying to parse some data to create an HTML select control, but am not really too familiar with PHP - can anyone help me out...

Here is a sample of the data...

[{"name":"","value":1,"target":null},{"name":"Bedfordshire","value":2,"target":null},{"name":"Berkshire","value":3,"target":null},{"name":"Buckinghamshire","value":4,"target":null}]

So basically my PHP script needs to echo out the options for my select control.

Many thanks,

Len

Re: Parsing issue

Posted: Mon Nov 15, 2010 9:19 am
by AbraCadaver
I'll leave the select control to you, but that string is json encoded so this will get you started:

Code: Select all

$objects = json_decode('[{"name":"","value":1,"target":null},{"name":"Bedfordshire","value":2,"target":null},{"name":"Berkshire","value":3,"target":null},{"name":"Buckinghamshire","value":4,"target":null}]');

foreach($objects as $o) {
  echo $o->name . ' = ' . $o->value;
}