2013-06-05 72 views
-2

HTML/JavaScript字符串我有一個問題: 我要提取之間 「體」的文字:{「文」:「 和 」,「 這發生2次在此。例如,這些是來自Facebook的評論,我想從兩個標準中提取文本並將它們放到單變量中,用換行符分隔,我使用的是PHP,已經將變量中的所有HTML都命名爲$ html。是代碼:提取文本從PHP

[ 
    { 
     "id":"537891442938686_1601777", 
     "fbid":"537891612938669", 
     "legacyid":"1601777", 
     "body":{ 
     "text":"Jaaa:D", 
     "ranges":[ 

     ], 
     "aggregatedranges":[ 

     ] 
     }, 
     "author":"1301211957", 
     "ftentidentifier":"537891442938686", 
     "likecount":0, 
     "hasviewerliked":false, 
     "canremove":false, 
     "canreport":false, 
     "canedit":false, 
     "source":null, 
     "istranslatable":false, 
     "timestamp":{ 
     "time":1370411670, 
     "text":"", 
     "verbose":"4. junij 2013 ob 22:54" 
     }, 
     "spamreplycount":0, 
     "replyauthors":[ 

     ], 
     "isfeatured":false 
    }, 
    { 
     "id":"537891442938686_1601790", 
     "fbid":"537895309604966", 
     "legacyid":"1601790", 
     "body":{ 
     "text":"Takteri\u010d \u017ee sodelujem?? Hmm 5i\u010d?", 
     "ranges":[ 

     ], 
     "aggregatedranges":[ 

     ] 
     }, 
     "author":"1087657810", 
     "ftentidentifier":"537891442938686", 
     "likecount":0, 
     "hasviewerliked":false, 
     "canremove":false, 
     "canreport":false, 
     "canedit":false, 
     "source":null, 
     "istranslatable":false, 
     "timestamp":{ 
     "time":1370412832, 
     "text":"", 
     "verbose":"4. junij 2013 ob 23:13" 
     }, 
     "spamreplycount":0, 
     "replyauthors":[ 

     ], 
     "isfeatured":false 
    } 
], 
"profiles":[ 
    { 
     "id":"1301211957", 
     "name":"Maja Lamov\u0161ek", 
     "firstName":"Maja", 
     "vanity":"zmaychee", 
     "thumbSrc":"https:\/\/fbcdn-profile-a.akamaihd.net\/hprofile-ak-ash4\/s32x32" 
    } 
] 

謝謝你們!!

+3

像'json_decode()函數搜索谷歌;' – DanFromGermany

回答

4

你的數據有JSON格式。我強烈建議解碼並將其放入一個對象中。之後,您可以輕鬆遍歷所有您需要的屬性。看看json_decode(http://php.net/manual/en/function.json-decode.php)。

+1

謝謝大家,這是一個在源搞砸代碼,對不起,我會再檢查一下json_decode –