【问题标题】:Extract text into string from html/javascript with php使用 php 将文本从 html/javascript 中提取为字符串
【发布时间】:2013-06-05 08:04:53
【问题描述】:

我有一个问题: 我必须在之间提取文本 “主体”:” 和 “,”。 在这个例子中这发生了 2 次,这些是来自 Facebook 的 cmets。我想从两个标准之间提取文本并将其放入单个变量,由换行符分隔。我正在使用 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_decode();的函数

标签: php html regex parsing extract


【解决方案1】:

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

【讨论】:

  • 谢谢大家,源代码弄乱了,对不起,我会检查json_decode
猜你喜欢
  • 2015-05-08
  • 2014-12-08
  • 1970-01-01
  • 2018-09-15
  • 1970-01-01
  • 1970-01-01
  • 2020-02-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多