如何使用php获取twitter的热门话题?

如何使用php获取twitter的热门话题?,php,twitter,Php,Twitter,你能给我一个php脚本谁返回twitter的第一个3趋势主题?谢谢我不确定你是否应该让别人为你写代码,但不管怎样,你在这里 <?php $request = file_get_contents( 'http://search.twitter.com/trends/current.json' ); $json = json_decode( $request, true ); $trends = $json[ 'trends' ]; $keys = ar

你能给我一个php脚本谁返回twitter的第一个3趋势主题?谢谢

我不确定你是否应该让别人为你写代码,但不管怎样,你在这里

<?php

$request    = file_get_contents( 'http://search.twitter.com/trends/current.json' );
$json       = json_decode( $request, true );
$trends     = $json[ 'trends' ];
$keys       = array_keys( $trends );
$trends     = $trends[ $keys[ 0 ] ];
$trends     = array(

     $trends[ 0 ][ 'name' ],
     $trends[ 1 ][ 'name' ],
     $trends[ 2 ][ 'name' ]

);

如果希望从
json_decode
中获得关联数组,可以将第二个参数
设置为true
,而不是获取对象然后强制转换它。+1。忘记了那个参数:)