PHP Feast--a collection of common functions

Source: Internet
Author: User
Tags date end explode functions string split variable trim

Recently wrote a lot of PHP, but also in touch with a lot of commonly used functions, most of them took notes, send a blog out to learn together. In fact, the feeling of learning a language, grammatical logic is soft quality, and the degree of familiarity with the language can only grow with the growth of the use of time, when the function of a language, library, characteristics are deeply understood, can barely be said to be skilled or proficient it.

1. Trim (), remove white space characters and other predefined characters from both ends of the string, and of course you can delete the specified characters.

Similarly, there are LTrim (), RTrim ().

2. __class__, this constant returns the name of the class when it is defined.

3. Strtotime (), describe the date and time of any English text as a Unix timestamp, such as Strtotime (' yesterday ') back to yesterday's Unix timestamp.

Often combined with date (), functions are used, such as date (' y-m-d h:i:s ', Strtotime (' Yesterday ')) to return to yesterday's date of the month and seconds.

4. Intval () converts any type argument other than an array or class to an integer type.

Similar to have floatval () and so on.

5. Explode (), the string by the specified character split into an array, very useful!!

6. file_get_contents (), read the entire file into a string.

The corresponding file_put_contents () can put a string into a file, you can put it directly into a text file, or you can split the output to a CSV file comma, you can open with Excel.

7. Php_eol, this constant represents a newline character. For example, the use of trim () is useful. PHP has many similar constants that represent the corresponding symbols.

8. Round (), you can keep the number of digits after the decimal point by the specified number of digits, rounded to save.

corresponding to the ceil () up, floor () down the whole, of course, you can also use the said Intval () directly just take the whole number ~.

9. Str_replace (), a very useful function that finds the specified character in the specified string and replaces it with the specified character.

Int_set (), you can pass in two string variable parameters so that one of the variables retains the specified value when the script runs, and restores the original value at the end of the script.

System (), executes an external program, and returns the result. Like executing a shell command.

Opendir () Opens a table of contents handle that can be preceded by a @ To hide the output of the error.

There are a number of corresponding file manipulation functions, such as chdir () to change the current directory to the specified directory. File_exists () to determine whether a file exists, unlink () is used to delete the specified file.

Array_shift () deletes the first element in the array and returns the value of the deleted element.

There are a number of corresponding array manipulation functions, such as array_flip () to flip the array key and Value,array_merge () to combine two or more arrays into an array, Array_diff_key () Returns an array that contains all the key values that are not in any other array in the array being compared. Array_unique () returns the array (which can be used to remove the repeating element) and Is_array () to determine whether the variable is an array (because PHP is a weakly typed language and therefore useful) , Array_slice () removes a value based on conditions in the array, array_values () returns an array of all the key values in a given array without preserving the key name.

Count (), which is intuitive to return the number of elements in an array.

Unset (), releasing the specified variable, such as clearing the value of the specified array.

Strpos () returns the position where the string first appears in another string.

Number_format (), the first argument is a decimal, the second argument is a fractional number, the third argument is a decimal symbol, and the fourth parameter is a comma-per-thousand symbol.

Implode () merges the array into a string according to the specified delimiter, corresponding to explode ().

File (), read the entire file into an array in which each cell is the corresponding row in the file.

Readdir () returns an entry in a table of contents handle opened by Opendir ().

Var_dump (), print the information about the variable.

Similar to the Print_r (), but the Var_dump () function is more detailed.

Constant () returns the value of a constant.

Feof () to detect whether the end of the file has been reached.

Fgets () reads a row from the file pointer.

STRCASECMP (), comparing two strings.

Chr (), returning characters from the specified ASCII code.

Stripslashes () deletes the backslash in the string.

Ucwords () to capitalize the first letter of each word in the string.

Method_exists () to check whether the method of the class exists.

Get_class () returns the class name of the object.

Extract () Imports the variable from the array into the current symbol table, the key name is used for the variable name, and the key value is used for the variable value.

Require (), include (), can implement a reference to the specified PHP script file, different from the way the error is handled, include () will produce a warning, continue execution, and require () will cause a fatal error, end the script.

33. Common MySQL operation function

Mysql_connect (), mysql_select_db (), Mysql_close (), mysql_query (), mysql_num_rows (), mysql_num_rows (), Mysql_free_ Result (), mysql_error ()

Mysql_num_fields () returns the number of fields in the result set

Mysql_field_table () returns the name of the table that contains the specified field

Mysql_field_name () Gets the field name of the specified field in the result

Mysql_fetch_row () returns a row from the result set as an array of numbers




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.