我有这段代码(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>';
?>
答案 0 :(得分: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;
...
答案 1 :(得分:0)
警告
仅限Windows:
此功能的Windows实现不支持%e修饰符。要获得此值,可以使用%#d修饰符。下面的示例说明了如何编写跨平台兼容的函数。
%z和%Z修饰符都返回时区名称而不是偏移或缩写。
<强>参考:强>