首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >strftime/strtotime语法

strftime/strtotime语法
EN

Stack Overflow用户
提问于 2013-02-01 23:56:36
回答 2查看 615关注 0票数 0

我有一段可用的代码(PHP)。我遇到的问题是strftime(‘%e%B’,strtotime($time));部分(在块的末尾)。它不返回任何内容..我做错了什么?可能是语法错误?

代码语言:javascript
复制
<?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>';

?>
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-02-02 00:09:42

是不是只有我还是你错过了一个echo?或者,您打算与.连接

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

应该是...

代码语言:javascript
复制
...
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; 
...
票数 2
EN

Stack Overflow用户

发布于 2013-02-02 00:02:28

警告

仅限Windows:

此函数的Windows实现不支持%e修饰符。要实现该值,可以改用%#d修饰符。下面的例子说明了如何编写跨平台兼容的函数。

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

参考:

  • http://php.net/manual/en/function.strftime.php
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14650117

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档