PHP Basics (ii) 1, random number and time 2, String function

Source: Internet
Author: User
Tags echo date php basics

One, random number and time
Random number generator (JS:math.random)
echo rand ();

Generate a random number in a range
echo rand (0,10);

Time stamp
echo Time ();

Format the display of time
echo "<br>";
echo Date ("Y-m-d h:i:s", Time ());
echo "<br>";
echo Date ("Y-m-d h:i:s", "101506494366");

Convert String to Timestamp
echo "<br>";
Echo strtotime ("2017-09-27 14:49:13");


echo "<br>";

Second, String function
Length Str.length
$str 1 = "ABCDEFG";
$str 2 = "ABCD";
Echo strlen ($str 1);
Comparison of two string lengths
echo "<br>";
Var_dump (strcmp ($str 1, $str 2));

Turn lowercase
echo "<br>";
Echo strtolower ("ABCDE");

Turn capital
echo "<br>";
Strtoupper ();
Splits a string, returns an array
echo "<br>";
Var_dump (Explode ("B", $str 2));

Stitching array elements into a single string
echo "<br>";
echo Implode ("|", ["a", "B", "C"]);

Find replacements
echo "<br>";
Echo str_replace ("CD", "CD", $str 1);

Replace the specified position character
echo "<br>";
Echo Substr_replace ($str 1, "xxx", 0, 3);

Intercept string
echo "<br>";
Echo substr ($str 1,1,3);

PHP Basics (ii) 1, random number and time 2, String function

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.