Nokki Posted June 10, 2009 Share Posted June 10, 2009 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. Link to comment https://forums.phpfreaks.com/topic/161665-solved-getting-specific-values-from-a-string/ Share on other sites More sharing options...
Mark Baker Posted June 10, 2009 Share Posted June 10, 2009 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); Link to comment https://forums.phpfreaks.com/topic/161665-solved-getting-specific-values-from-a-string/#findComment-853035 Share on other sites More sharing options...
Nokki Posted June 10, 2009 Author Share Posted June 10, 2009 Managed to solve this with your help - Thanks Link to comment https://forums.phpfreaks.com/topic/161665-solved-getting-specific-values-from-a-string/#findComment-853268 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.