PHP's common library of functions

Source: Internet
Author: User
Tags echo date time and date

1. Time and date
    • How to get timestamp time ()-Number of milliseconds since 1970
echo Time ();
    • Date
echo Date (' y-m-d h:i:s ');
    • Get the default time zone
Echo Date_default_timezone_get ();
    • The default time is not the same as the local computer time, you need to set the appropriate time zone
Date_default_timezone_set (' Asia/shanghai '); Set to Shanghai's time zone echo date (' y-m-d h:i:s ');
    • Convert the timestamp into a date.
echo Date (' y-m-d h:i:s ', Time ()), Echo ' <br/> ', echo date (' y-m-d h:i:s ', Time ());

Operation of 2.JSON Format data
    • JSON-formatted data
Arrays can be nested (arrays containing arrays) can also contain objects (values and names correspond to internal data, key-value pairs) [1,2,5,7,8, "Hello", [6,7,8],{"H", "Hello"}] {"H": "Hello", "W": "World", [ [+]}
    • Arrays generate JSON-formatted data encode
$arr = Array (1,2,5,8, "Hello", "Cqut", Array ("h" + = "Hello", "name" = "Cqut")); echo ' array format = '. ' <br/> ';p rint_r ($arr); Echo ' <br/> '; echo ' json formate = '. ' <br/> '; Echo json_encode ($arr);//json_encode convert an object to JSON-formatted data
Output array format = =
Array ([0] = 1 [1] = 2 [2] = 5 [3] = 8 [4] = = [5] = = Cqut [6] + = Array ([h] = = [ Name] = Cqut))
JSON formate = [1,2,5,8, "Hello", "Cqut", {"H": "Hello", "name": "Cqut"}]
    • Object generates JSON-formatted data encode
$obj = Array (' h ' = = ' Hello ', ' w ' = ' World ', array (+/-)); Echo Json_encode ($obj);
Output {"H": "Hello", "W": "World", "0": [All-in-all]}
    • Convert JSON-formatted data to PHP objects decode
$jsonStr = ' {' h ': ' Hello ', ' W ': ' World ', ' 0 ': [[n] '; $obj = Json_decode ($jsonStr);p rint_r ($obj); Echo ' <br/> '; Echo $obj->h;
Output StdClass Object ([h] = = Hello [W] = [0] = = Array ([0] = 1 [1] = 2 [2] = 3)) Hello

PHP's common library of functions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.