"PHP" Basic Learning

Source: Internet
Author: User
Tags sprintf

Summary:

Basic Knowledge Review

1) array

2) string

3) Time

One, array

1.1 Array Classification
Indexed arrays: Regular arrays
Associative arrays: Key-value pairs

Second, string

2.1 Defining strings
HEREDOC syntax structure-defined string:
$hello = <<<tag
Hello World
TAG;

2.2 What is the difference between a single quote and a double quote?
PHP allows us to include string variables directly in a double quote string.
The contents of a single quote string are always considered ordinary characters.

Example:
$str = ' Hello ';
echo "STR is $STR"; Run Result: STR is hello
Echo ' str is $STR '; Operation Result: STR is $STR

2.3 Removing spaces
Trim removes the leading and trailing spaces
LTrim Remove the first space
RTrim Remove Trailing blanks

2.4 Calculating string Lengths
Strlen
Mb_strlen Calculating Chinese string length

2.5 string interception
SUBSTR (string variable, start intercept position, intercept number)
MB_SUBSTR (string variable, start intercept position, intercept number, Web page encoding) Chinese string intercept function

2.6 Finding a string
Strpos (string to be processed, string to position, starting position of position [optional])

2.7 Replacement string
Str_replace (The string to find, the string to replace, the string to be searched, and the replacement to count [optional])

2.8 format string
sprintf (format, string to convert)
Example: sprintf ('%.3f ', $str);

2.9 Merging and splitting of strings
Implode (delimiter [optional], array) Merge functions
Explode (delimiter [optional], string) separator function

2.10 Escaping
Addslashes (String)
Example:
$str = "What ' s your name?";
echo addslashes ($STR);//output: what\ ' s your name?

Three, time

3.1 Getting Unix timestamps
Time ()

3.2 Timestamp formatting
Date (' y-m-d ', timestamp)

3.3 formatted time converted to timestamp
Strtotime (' 2015-07-01 '); As long as the date can be formatted time, can be converted to timestamp, the interior will automatically recognize

3.4 Calculation Time
Strtotime (Time string to parse, calculates the timestamp of the return value "default is the current time, optional")

Strtotime ("Now"); Current time
Strtotime ("+5 seconds"); 5 Seconds after current time

3.5 GMT
Gmdate (' y-m-d h:i:s ', timestamp); Greenwich Mean Time (GMT), which is now Chinese time zone minus 8 hours, so 8 hours less than the current time

"PHP" Basic Learning

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.