Jump to content

[SOLVED] Getting specific values from a string


Nokki

Recommended Posts

Hi there,

 

I wouldl like to ask if anyone knows of a reliable way to extract data from a string. What I am looking for is the name values.

 

So for example:

 

{"trends":{"2009-06-10 13:25:10":[{"query":"AT&T","name":"AT&T"},{"query":"\"Adam Lambert\"","name":"Adam Lambert"},{"query":"iPhone","name":"iPhone"},{"query":"Apple","name":"Apple"},{"query":"\"Nick Griffin\"","name":"Nick Griffin"},{"query":"\"Father\u2019s Day\"","name":"Father\u2019s Day"},{"query":"BNP","name":"BNP"},{"query":"Magic","name":"Magic"},{"query":"Goodmorning","name":"Goodmorning"},{"query":"Lakers","name":"Lakers"}]},"as_of":1244640310}

 

should result in:

 

AT&T

Adam Lambert

iPhone

Apple

Father's Day

BNP

Magic

Goodmorning

Lakers

 

I want to insert the single words into a mysql database after I got the values like

 

MySQL_Query("insert ignore into words values('$extractedword')") or die(mysql_error());

 

Maybe someone is able to help me with this task?

 

Thanks a lot and excuse me if this question is very newbie like. I am trying to learn and I looked up a lot of things about JSON (thats what this string is about), however, everything failed so far so I am looking to do it like this cause it teaches me more about grabbing values from a string.

Try starting with:

$line = '{"trends":{"2009-06-10 13:25:10":[{"query":"AT&T","name":"AT&T"},{"query":"\"Adam Lambert\"","name":"Adam Lambert"},{"query":"iPhone","name":"iPhone"},{"query":"Apple","name":"Apple"},{"query":"\"Nick Griffin\"","name":"Nick Griffin"},{"query":"\"Father\u2019s Day\"","name":"Father\u2019s Day"},{"query":"BNP","name":"BNP"},{"query":"Magic","name":"Magic"},{"query":"Goodmorning","name":"Goodmorning"},{"query":"Lakers","name":"Lakers"}]},"as_of":1244640310}';

$dataLine = json_decode($line);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.