1

我知道过滤多种类型是这样工作的:

https://www.googleapis.com/freebase/v1/topic/m/0d6lp?filter=/common/topic/notable_for&filter=/common/topic/alias

但是当我必须用 PHP 编写这个时,我不知道该怎么做。

$service_url = 'https://www.googleapis.com/freebase/v1/topic';
$mid = '/m/0d6lp';
$params = array('key'=>$API_KEY, 'filter' => '/common/topic/notable_for', 'filter' => '/common/topic/alias');
$url = $service_url . $mid . '?' . http_build_query($params);

当我卷曲 $url 时,只有最后一个过滤器 (/common/topic/alias) 生效,显然是因为“过滤器”键在数组 $params 中出现了两次,并且只采用了最新键的值。

如何在 PHP 数组中构造以下 url?

https://www.googleapis.com/freebase/v1/topic/m/0d6lp?filter=/common/topic/notable_for&filter=/common/topic/alias 
4

1 回答 1

1

我不确定你想做什么。如果您只想使用多个过滤器执行查询,您可以直接将它们添加到 url 字符串中,如下所示:

https://www.googleapis.com/freebase/v1/topic/m/0d6lp?key= $API_KEY&filter=/common/topic/notable_for&filter=/common/topic/alias

您不需要使用任何数组,只需将 url 构造为普通的 php 字符串。如果您仍然希望在数组中包含参数,我建议您对数组中的所有元素进行 foreach 循环以构造字符串,然后使用字符串作为 curl 的参数。

于 2013-07-10T14:35:39.043 回答