: This article describes common php functions. if you are interested in the PHP Tutorial, refer to it. Common php functions:
String processing functions:
Powerful:
1. other types of data are used in string processing functions and will be automatically converted to strings before processing.
2. strings can be treated as arrays and as character sets.
For example: $ str = "lijian"; echo $ str [1]; but this will lead to the mistaken thought of as an array, so it is usually written as follows: echo $ str {1 };
Extract the first two characters: echo $ str [0]. $ str [1];
All the string processing functions in php are not modified on the original character, but return a newly formatted string.
Trim (); space is deleted by default. Note that the deletion here is not a real deletion.
Trim ($ str, '0 .. 9. '); delete 0 to 9, point, and space
Ltrim ($ str, '1'); delete the number 1 on the left.
Rtrim ($ str, '0 .. 9'); delete 0 to 9
Str_pad ($ str, 10, '*', STR_PAD_BOTH );
Html-related:
Strip_tags (); retrieves HTML tags
Htmlspecialchars (stripslashes ($ str); materialized the string and removes the backslash
Nl2br;
Htmllentities ();
Stripslashes (); removes diagonal lines
Number_format (); format function
Strrev (); reverse
Encryption:
Md5 ();
Md5_file ();
String comparison functions:
Strcmp (); binary security string comparison
Strcasecmp (); binary secure string comparison, case insensitive
Strnatcmp (); use a natural sorting algorithm to compare strings
Strstr (): Case Sensitive, returns the string from where the matching starts
Stristr (): Case insensitive
Stripos (): Locate the first occurrence of a string, case insensitive
Strpos (): Locate the first occurrence of a string, Case Sensitive
Strrpos (): searches for the final position of a string, case sensitive.
Strripos (): searches for the final position of a string, case insensitive.
Substr (): There are other substring
It can be automatically converted into a string, for example, substr (123456,2, 4 );
Str_replace (string, string, string): replace one with one.
Str_replace (array, string, string): replace multiple replace into one
Str_replace (array, array, string): replace multiple with multiple
Str_ireplace (): case-insensitive
Explode (): converts a string to an array.
Implode (): converts an array to a string.
Array functions:
Array_map ();
What are the differences between mysqli_fetch_assoc () and mysqli_fetch_row () and mysqli_fetch_object?
Both mysqli_fetch_assoc () and mysqli_fetch_row () are used to return the query results to an array. both return the first row and move the pointer down the row.
Difference: mysqli_fetch_assoc () is indexed with a keyword. For example:
$ Row = $ result-> fetch_assoc ();
Echo $ row ['username'];
However, mysqli_fetch_row () uses the numeric index value. For example:
$ Row = $ result-> fetch_row ();
Echo $ row [0]; // note: "0" indicates the first field in the table (that is, username is the first field in the table ).
Another function: mysqli_fetch_object () is used to return a row to an object, and then take the value through the class method, for example:
$ Row = $ result-> fetch_object ();
Echo $ row-> username;
The above section describes common php functions, including related content, and hopes to help those who are interested in the PHP Tutorial.