Parsing issue

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
len_hulley
Forum Newbie
Posts: 1
Joined: Mon Nov 15, 2010 1:32 am

Parsing issue

Post 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
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Parsing issue

Post 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;
}
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply