凤眠

先行后知,知行合一

导航

代码片段

Posted on 2015-04-17 12:45  凤眠  阅读(154)  评论(0编辑  收藏  举报

$fp = fopen($filename, "w");
fwrite($fp, json_encode($userinfo));
fclose($fp);

 

date("H:i:s");

 

SELECT * FROM t_details WHERE nickname IS NULL

 

if (strlen($foo) < 5) { echo “Foo is too short”; }
vs.(与下面的技巧做比较)
if (!isset($foo{5})) { echo “Foo is too short”; }

 

$blog = '博客园';

echo 'Hello!',$blog,'this a IT blog';

    public function getFriendlyTime($timestamp)
    {
        $thisYear = date("Y");
        $thisMonth = date("n");
        $thisDay = date("j");

        $someYear = date("Y", $timestamp);
        $someMonth = date("n", $timestamp);
        $someDay = date("j", $timestamp);
        if ($someYear == $thisYear) {
            if ($someMonth == $thisMonth) {
                if ($thisDay == $someDay) {
                    return date("H:i:s", $timestamp);
                }

                return date("n月j日 H:i", $timestamp);
            }

            return date("n月j日 H:i", $timestamp);
        }

        return date("Y年n月j日 H:i", $timestamp);
    }
    public function getFixedLengthString($string, $length = 6)
    {
        if (mb_strlen($string, "UTF-8") > $length)
        {
            return mb_substr($string, 0, $length, "UTF-8")."...";
        }

        return $string;
    }