亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何從php中的知識圖api中僅提取文章正文?

如何從php中的知識圖api中僅提取文章正文?

PHP
料青山看我應如是 2022-01-02 20:14:24
我試圖只從 php 中的 json-ld 獲取文章正文,但我不明白如何。我對從 php 編碼和解碼 json 不太熟悉,所以似乎沒有任何效果。  "@context": {    "@vocab": "http://schema.org/",    "goog": "http://schema.googleapis.com/",    "resultScore": "goog:resultScore",    "detailedDescription": "goog:detailedDescription",    "EntitySearchResult": "goog:EntitySearchResult",    "kg": "http://g.co/kg"  },  "@type": "ItemList",  "itemListElement": [    {      "@type": "EntitySearchResult",      "result": {        "@id": "kg:/m/0dl567",        "name": "Taylor Swift",        "@type": [          "Thing",          "Person"        ],        "description": "Singer-songwriter",        "image": {          "contentUrl": "https://t1.gstatic.com/images?q=tbn:ANd9GcQmVDAhjhWnN2OWys2ZMO3PGAhupp5tN2LwF_BJmiHgi19hf8Ku",          "url": "https://en.wikipedia.org/wiki/Taylor_Swift",          "license": "http://creativecommons.org/licenses/by-sa/2.0"        },        "detailedDescription": {          "articleBody": "Taylor Alison Swift is an American singer-songwriter and actress. Raised in Wyomissing, Pennsylvania, she moved to Nashville, Tennessee, at the age of 14 to pursue a career in country music. ",          "url": "http://en.wikipedia.org/wiki/Taylor_Swift",          "license": "https://en.wikipedia.org/wiki/Wikipedia:Text_of_Creative_Commons_Attribution-ShareAlike_3.0_Unported_License"        },        "url": "http://taylorswift.com/"      },      "resultScore": 896.576599    }  ]}我只需要文章正文“泰勒·艾莉森·斯威夫特是美國創作歌手兼演員……”。我如何實現這一目標?
查看完整描述

1 回答

?
慕俠2389804

TA貢獻1719條經驗 獲得超6個贊

您必須使用json_decode解碼此字符串,然后它只是從數組中獲取您的需求。例如


$j = '{"@context": {"@vocab": "http://schema.org/", "goog": "http://schema.googleapis.com/", "resultScore": "goog:resultScore" }}';


$arr = json_decode($j, true);


echo $arr['@context']['goog'];

因為articleBody它應該是:


$arr['itemListElement'][0]['result']['detailedDescription']['articleBody']


查看完整回答
反對 回復 2022-01-02
  • 1 回答
  • 0 關注
  • 139 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號