PHP Advanced 1

Source: Internet
Author: User
Tags rtrim time and date value of pi truncated

1.php Time function

The UNIX timestamp (called: timestamp) is an important concept in PHP for time and date, which represents the sum of the seconds from January 1, 1970 to the current time. PHP provides a built-in function time () to get the timestamp of the current time of the server.

(1) Date ()

PHP has a date () function built into it to get the current day and time. Format: Date (timestamp format, specified timestamp "optional")

Var_dump (Date ("y-m-d h:i:s"));//2016-11-16 21:10:13

Var_dump (Date ("y-m-d h:i:s"));//16-11-16 09:10:13

Var_dump (Date ("Y-m-d h:i:s", 1472903021));//returns the specified time

Var_dump (Date ("Z w"));//321 4

Microtime () function:

Returns the current microsecond and timestamp (returns a floating-point number if the given argument is true)

Var_dump (Microtime ()); 0.68103500 1479302563

Var_dump (Microtime (true)); 1479302563.6811

GETDATE () function:

Gets the current time or the text time of the specified timestamp (array form)

Thus, the equivalent can be obtained by the month and day respectively.

Date_default_timezone_set (' PRC ');Var_dump(Date_default_timezone_get ());Var_dump( Time());//int 1479367657Var_dump(Date("y-m-d h:s:d"));//2016-11-17 15:37:17Var_dump(Date("Y-m-d h:s:d", 1429366997));//2015-04-18 22:17:18Var_dump(Date("W-z"));//4-321 weeks Four This is 321 days of the yearVar_dump(Strtotime("2011-11-11"));//1320940800Var_dump(Strtotime("2011-11-11 00:00:11"));//1320940811Var_dump(Microtime());//0.39642800 1479367657Var_dump(Microtime(true));//1479367657.3964Var_dump(getdate());//ArrayVar_dump(getdate() [' Month ']);//November

2.php Math functions:

Ceil (): function rounded up to the nearest integer, return float type

Floor (): The function rounds down to the nearest integer, returning float type

Max (): function returns maximum value

MIN (): function returns the minimum value

Round (): Rounding of floating-point numbers (type float after conversion)

Mt_rand (Min, max): Returns a random integer between Min and Max

Pow (x, y): Calculates the quadratic value and returns the Y-order of X

PI (): Returns the value of pi

3. String manipulation:

If we use variables in double quotes, we can use {} to keep the variables.

$str 1 = "I am a string";

echo "abcde{$str 1}12345";

When we display special symbols in a string, we can use the escape character output.

echo "nihao\\n all Good";

Output: nihao\n Hello, everyone.

(1) String manipulation:

Trim ("Bokanwensi"): Returns a string that removes the whitespace from the string;

LTrim ("Bokanwensi"): Returns a string that deletes the left space of the string

RTrim ("Bokanwensi"): Returns a string that removes whitespace to the right of the string;

Strlen ("Bo see Evans"); A function that obtains the length of a string;

Mb_strlen ("Bo see Evans", "Utf-8"); A function that gets the length of the string, optionally encoding the format

Strtolower (): Convert all strings to lowercase

Strtoupper (): Convert string to uppercase string

Ucfirst (): Change the first letter of the string to uppercase

Ucwords (): Change the first letter of each word in a string to uppercase

Explode (".", "www.baidu.com"): Splits a string into an array according to rules and returns a new array substr (string, int start, int [length ]): Returns the truncated string, and the countdown is truncated if start is negative

Mb_substr (): Return intercept string, third parameter can modify encoding format (utf-8,gbk,gb2312)

Note: The system does not support MB_SUBSTR () in the php.ini to find Mbstring.dll; Extension=php_mbstring.dll to remove the previous;

STRCHR (data source, specified character): Starts at the beginning of the specified character, and then returns the Intercept character.

STRRCHR (data source, specified character): Starts at the end of the specified character, and returns the Intercept character.

Str_replace (parameter 1, parameter 2, Parameter 3): Parameter 1 is the replacement target, parameter 2 is the replacement content, parameter 3 is the query data source str_ireplace (parameter 1, parameter 2, Parameter 3): and Str_replace Consistent but case insensitive

MD5 (): Returns the encrypted string (irreversible encryption);

UrlEncode (): The principle of encode the URL is to first convert Chinese characters to 16, and then precede each character with an identifier%

UrlDecode (): Decrypts a URL to decode an encoded URL string by converting a hexadecimal string to a Chinese character

$str 1= ' abc ';Echo"I am a painter$str 1";//I'm a painter, abc .Echo"I am a painter$str 1 Painting Skills";//error, and then show ' I'm a painter 'Echo"I am a painter {$str 1} Strong ability ";//I'm a painter, ABC is strong .$str 2= ' Hsshidoubi ';Var_dump(Trim($str 2));//String TenVar_dump(LTrim($str 2));//stringVar_dump(RTrim($str 2));//stringVar_dump(strlen($str 2));//int$STR 3= ' Bo See Evans 12 ';Var_dump(strlen($STR 3));//intVar_dump(Mb_strlen ($STR 3, ' Utf-8 '));//int 6
$str 1= ' 123jizhimingjizhim456 ';Var_dump(STRCHR($str 1, ' m '));//mingm456Var_dump(STRRCHR($str 1, ' m '));//m456Var_dump(Str_replace(' Jizhi ', ' Lihai ',$str 1));Var_dump(Str_ireplace(' Jizhi ', ' Lihai ',$str 1));$pass= ' Hssdb ';Var_dump(MD5($pass));Var_dump(MD5(MD5($pass.‘ DB '));//Stitching a characterfunctionFnMD5 ($str){    return MD5(MD5($str.‘ Hs));}Var_dump(FnMD5 (' 12345 '));
$str= "Big Tiger egg Babbling"; Var_dump (Mb_substr ($str, 0,6)); // Big Tiger Var_dump (Mb_substr ($str, 0,5)); // garbled Var_dump (Mb_substr ($str, 0,6, ' utf-8 ')); // big tiger eggs are babbling

4. Uploading Files

Super global variable $_files

$_files-Store all kinds of information related to uploading files

$_files["File" ["Name"]-the name of the file being uploaded

$_files["File" ["type"]-the type of file being uploaded

$_files["File" ["Size"]-the size of the uploaded file, measured in bytes

$_files["File" ["Tmp_name"]-the temporary copy name of the uploaded file

$_files["File" ["Error"]-error code resulting from uploading a file 0 1 2 3 4

File_exists () function

The file_exists () function checks whether a file or directory exists

Returns true if the specified file or directory exists, otherwise false

File_exists (path) path Specifies the paths to check

Example: File_exists ("upload/". $_files["File" ["Name"])

Move_uploaded_file () function

Move_uploaded_file () function

Move the uploaded file to a new location returns true if successful, otherwise false

Move_uploaded_file (file, Newloc)

file specifies the files to be moved

Newloc new location of the required documents

Example: Move_uploaded_file ($_files["file"] ["Tmp_name"], "upload/". $_files["File" ["name"]);

Other settings

The enctype attribute of the <form> tag specifies what type of content to use when submitting a form.

Use "Multipart/form-data" when the form requires binary data, such as the contents of a file.

The type of the IE recognition jpg file must be pjpeg, and Firefox must be a jpeg.

<?PHPVar_dump($_files);if(!Empty($_files)) {    if((($_files[' File '] [' type ']== ' image/jpeg ') | | ($_files[' File '] [' type ']== ' image/png ') | | ($_files[' File '] [' type ']== ' image/gif ') | | ($_files[' File '] [' type ']== ' Image/pjpeg ')) && ($_files[' File '] [' Size ']<=102400)) {        if($_files[' File '] [' Error ']=0) {            if(file_exists("upload/".$_files["File"] ["Name"])){                Echo $_files["File"] ["Name"]. " File already exists "; }Else{                Move_uploaded_file($_files[' File '] [' Tmp_name '], "upload/".$_files[' File '] [' Name ']); }        }Else{            Echo"Error number is:".$_files[' File '] [' Error ']; }    }Else{        Echo $_files[' File '] [' name ']. " Error File "; }}? ><! DOCTYPE html>

PHP Advanced 1

Related Article

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.