如何从维基百科中提取标题 API

How to Extract the Title from the Wikipedia API

这可能是一个明显的答案,我只是没有得到,因为我已经在这几个小时了。所以从这个 Wikipedia API query 我得到了这个回复

{"batchcomplete":"","continue":{"sroffset":1,"continue":"-||"},"query":{"searchinfo":{"totalhits":173918},"search":[{"ns":0,"title":"Google","snippet":"search engine, see Google Search. For other uses, see Google (disambiguation). Not to be confused with Goggle\u00a0or Googol. Google Inc. is an American","size":143977,"wordcount":13927,"timestamp":"2015-11-25T08:44:48Z"}]}}

我已经转换成这个php数组

Array
(
[batchcomplete] => 
[continue] => Array
    (
        [sroffset] => 1
        [continue] => -||
    )

[query] => Array
    (
        [searchinfo] => Array
            (
                [totalhits] => 173918
            )

        [search] => Array
            (
                [0] => Array
                    (
                        [ns] => 0
                        [title] => Google
                        [snippet] => search engine, see Google Search.  For other uses, see Google (disambiguation). Not to be confused with Goggle or Googol. Google Inc. is an American
                        [size] => 143977
                        [wordcount] => 13927
                        [timestamp] => 2015-11-25T08:44:48Z
                    )

            )

    )

)

我正在尝试使用此代码从数组中提取标题实体

echo $array->query->search->0->title;

我做错了什么?

您使用的是 stdClass 对象,

echo $array->query->search->0->title;

->替换为[]

echo $array['query']['search'][0]['title'];