0

我有这段工作代码(PHP)。我遇到的问题是 strftime('%e %B',strtotime($time)); 部分(位于块的末尾)。它什么也没返回..我做错了什么?也许是语法错误?

<?php
function buildBaseString($baseURI, $method, $params)
{
    $r = array();
    ksort($params);
    foreach($params as $key=>$value){
        $r[] = "$key=" . rawurlencode($value);
    }

    return $method."&" . rawurlencode($baseURI) . '&' . rawurlencode(implode('&', $r)); //return complete base string
}

function buildAuthorizationHeader($oauth)
{
    $r = 'Authorization: OAuth ';
    $values = array();
    foreach($oauth as $key=>$value)
        $values[] = "$key=\"" . rawurlencode($value) . "\"";

    $r .= implode(', ', $values);
    return $r;
}

$url = "https://api.twitter.com/1.1/statuses/user_timeline.json";

$oauth_access_token = "XXXXXX";
$oauth_access_token_secret = "XXXXXX";
$consumer_key = "XXXXXX";
$consumer_secret = "XXXXXX";

$oauth = array( 'oauth_consumer_key' => $consumer_key,
    'oauth_nonce' => time(),
    'oauth_signature_method' => 'HMAC-SHA1',
    'oauth_token' => $oauth_access_token,
    'oauth_timestamp' => time(),
    'count' => 6,   
    'oauth_version' => '1.0');

$base_info = buildBaseString($url, 'GET', $oauth);
$composite_key = rawurlencode($consumer_secret) . '&' . rawurlencode($oauth_access_token_secret);
$oauth_signature = base64_encode(hash_hmac('sha1', $base_info, $composite_key, true));
$oauth['oauth_signature'] = $oauth_signature;


$header = array(buildAuthorizationHeader($oauth), 'Expect:');
$options = array( CURLOPT_HTTPHEADER => $header,
    CURLOPT_HEADER => false,
    CURLOPT_URL => $url . '?count=6',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_SSL_VERIFYPEER => false);

$feed = curl_init();
curl_setopt_array($feed, $options);
$json = curl_exec($feed);
curl_close($feed);

$twitter_data = json_decode($json);

echo "
            <ul style='color:#6E6E6E'>";

foreach ($twitter_data as $tweet)
{
    if (!empty($tweet)) {
        $text = $tweet->text;
    }
    if (!empty($tweet)) {
        $id = $tweet->id;
    }
    if (!empty($tweet)) {
        $time = $tweet->created_at;
    }
    if (!empty($tweet)) {
        $username = $tweet->user->name;
    }
    echo '<li>';
    echo $text . "<br><a href=\"http://twitter.com/";
    echo $username ;
    echo '/status/';
    echo $id ;
    echo '"><small>';
    strftime('%e %B',strtotime($time));
    ' </small></a> - <a href="http://twitter.com/intent/tweet?in_reply_to=';
    echo $id;
    echo '"><small>rispondi</small></a> - <a href="http://twitter.com/intent/retweet?tweet_id=';
    echo $id;
    echo '"><small>retweet</small></a> - <a href="http://twitter.com/intent/favorite?tweet_id=';
    echo $id;
    echo '"><small>preferito</small></a></li>';
}

echo '
            </ul>';

?>
4

2 回答 2

2

只是我还是你只是错过了一个echo?还是您打算与 连接.

...
echo $id ;
echo '"><small>'; 
strftime('%e %B',strtotime($time)); ' </small></a> - <a href="http://twitter.com/intent/tweet?in_reply_to='; 
echo $id;
...

应该...

...
echo $id ;
echo '"><small>'; 
echo strftime('%e %B',strtotime($time));
echo ' </small></a> - <a href="http://twitter.com/intent/tweet?in_reply_to='; 
echo $id; 
...
于 2013-02-01T16:09:42.373 回答
0

警告

仅限 Windows:

此函数的 Windows 实现不支持 %e 修饰符。为了达到这个值,可以使用 %#d 修饰符。下面的例子说明了如何编写一个跨平台兼容的函数。

%z 和 %Z 修饰符都返回时区名称而不是偏移量或缩写。

参考:

于 2013-02-01T16:02:27.860 回答