用php从html/javascript中提取文本到字符串


Extract text into string from html/javascript with php

我有一个问题:我必须从中提取文本"身体":{"文本":"answers","。在这个例子中出现了2次,这些是来自Facebook的评论。我想提取并把文本从两个标准之间到单个变量,由换行符分隔。我用的是PHP,已经得到了整个HTML在变量名为$ HTML。

代码如下:

[
   {
      "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"
   }
]

谢谢你们了! !

这里的数据是JSon格式的。我强烈建议将其解码并放入对象中。之后,您可以轻松地遍历所需的所有属性。看一下json_decode (http://php.net/manual/en/function.json-decode.php)。