PHP commonly used functions ____ functions

Source: Internet
Author: User
Tags abs chr compact numeric value ord pow square root strtok
PHP Common function Summary mathematical function 1.  ABS (): the absolute value $abs = ABS (-4.2); 4.2 Numeric value Absolute number 2.  Ceil (): Take the whole echo ceil (9.999) in one method; 10 floating-point number into a whole 3.  Floor (): To take the whole echo floor (9.999); 9 floating point number direct shed to the decimal part of 4. Fmod (): floating-point number? 1 2 3 4
$x = 5.7;  $y = 1.3; Two floating-point numbers, x>y floating point remainder $r = Fmod ($x, $y); $r equals 0.5, because 4 * 1.3 + 0.5 = 5.7
5. POW (): Returns the number of N-Second square echo POW (-1, 20); 1 Base Number |n The second square of the value of 6.  Round (): Floating-point number rounded echo round (1.95583, 2); 1.96, a number | Keep the number of digits after the decimal point, the default is 0 rounded results 7.  sqrt (): square root echo sqrt (9); 3 square root 8.  Max (): Max Echo Max (1, 3, 5, 6, 7);  More than 7 digits or arrays return the maximum value of Echo max (Array (2, 4, 5)); 5 9. Min (): Minimum value input: multiple digits or array output: Returns the minimum value of 10.  Mt_rand (): Better random number input: Minimum | Maximum, output: Random number of random returns within the range of the value of Echo mt_rand (0, 9); N 11.  Rand (): Random number input: Min | Maximum, output: Random number of random return range within the value of 12. Pi (): Gets the pi value to go to a space or other character: 13.    Trim (): Remove spaces or other predefined characters at each end of the string? 1 2 $str = "\r\nhello world!\r\n"; echo Trim ($STR);
Input: Target string return value: The string 14 after the purge.    RTrim (): Delete space or other predefined characters to the right of the string? 1 2 $str = "Hello world!\n\n"; echo RTrim ($STR);
Chop (): Alias 16 of RTrim (). LTrim (): Deletes a space or other predefined character to the left of the string
? 1 2 $str = "\r\nhello world!"; Echo LTrim ($STR);
DirName (): Returns the directory part of the path echo dirname ("c:/testweb/home.php"); C:/testweb input: A string return value containing a path: Returns the directory partial string generation and transformation of the file path: 18.    Str_pad (): Fill the string to the specified length? 1 2 $str = "Hello World"; Echo Str_pad ($str, 20, ".");
Enter: the string to fill |  Length of new String | String used for padding, default is blank output: finished string 19.  Str_repeat (): Repeats use of the specified string echo str_repeat (".", 13); String to repeat | The number of times the string will be repeated 13 point 20. Str_split (): Splits the string into an array print_r (Str_split ("Hello"));  Enter: String to split | The length of each array element, the default 1 output: A split string array of 21.  Strrev (): Invert string echo strrev ("Hello world!"); !dlrow Olleh Output: String 22 after the reverse order of the target string.    WordWrap (): Wrap the string in a specified length? 1 2 3
$STR = "An example on a long word is:supercalifragulistic"; Echo WordWrap ($STR, 15);
Input: Target string | Maximum width output: The new string 23 after the line is folded. Str_shuffle (): Randomly disrupts all characters in the string echo str_shuffle ("Hello World"); Input: Target string sequential output: scrambled string 24.    PARSE_STR (): Parse a string into a variable? 1 2 parse_str ("Id=23&name=john%20adams", $myArray); Print_r ($myArray);
Enter the array name output:  The string  |  storage variable to parse:  return array ([id]  =>  23[name]  =>  john&nbsp ; Adams) 25. Number_format ():  to format numbers   input via thousands group number  |  specify how many decimal  |  rules are used as the character   string for the decimal point |   The string output used as the thousand separator:  1,  000,  000  1,  000. 00  1.000. 000,  00 Case conversion: 26. Strtolower ():  string to lowercase echo  strtolower ("hello world!"); Target string   lowercase string 27. The Strtoupper ():  string is converted to uppercase echo  Strtoupper ("hello world!"); Output:  Uppercase string 28. Ucfirst ():  string initial capitalization echo  Ucfirst ("Hello world"); //Hello world 29. Ucwords ():  string The first character of each word to uppercase echo  ucwords ("Hello world"); //Hello world HTML Tag Association: 30. Htmlentities ():  convert a character to an HTML entity   ?    1 2   $str  =  "john &  ' Adams"; echo  htmlentities ($str,  ent_compat); // john &  ' Adams '
Htmlspecialchars (): Predefined words Fu Jing HTML encoding 32. NL2BR (): \ n escaped for < br > tag echo nl2br ("One line.\nanother line."); Output: Processed string 33.strip_tags (): Stripped HTML, XML, and PHP tags echo strip_tags ("Hello < b >world! </B > ");   34.addcslashes (): Add a backslash before the specified character to escape the character in the string? 1 2 3
$str = "Hello, my name is John Adams"; Echo $str; Echo addcslashes ($str, ' m ');
Input: Target string | Specifies a specific character or range of characters 35.stripcslashes (): Deletes the backslash echo stripcslashes ("Hello, \my Na\me is Kai ji\m") added by Addcslashes (). The target string Hello, my name is Kai Jim. 36.addslashes (): Add backslashes before specifying predefined characters $str = "Who's John Adams?"; echo addslashes ($STR); Output: Escaping the ' "\ and null in the target string 37.stripslashes (): Deletes the escape character Echo stripslashes (" Who\ ' John Adams ") added by Addslashes (); Clear escape symbol who ' s John Adams?   38.quotemeta (): Add a backslash before certain predefined characters in the string? 1 2 3
$STR = "Hello World". (Can you hear me?) "; echo Quotemeta ($STR); Hello world\. \ (Can you hear me\?\)
39.CHR ():  returns the character ECHO&NBSP;CHR (052); // ascii  value from the specified  ASCII  value returns the corresponding character 40.ord ():  Returns the ASCII value of the first character of the string Echo ord ("Hello");  string comparison of the first character  ASCII  value string: 41.strcasecmp ():  Case-insensitive comparison of two string echo strcasecmp ("hello world!",  "hello world!"); Enter:  two target string   output:  1 |  0 |  small  - 1 42.strcmp ():  case sensitive comparison two string 43. STRNCMP ():  compares the first n characters of a string,  a case-sensitive call: int strncmp  (string  $str 1 , string   $STR 2 , int  $len) 44.strncasecmp ():  Compare the first n characters of a string,  case-insensitive calls: int  strncasecmp  (string  $str 1 , string  $str 2 , int  $len  ) 45.strnatcmp ():  Natural order method to compare string length,  case-sensitive call: int strnatcmp  (string  $str 1 , string $ str2 ) Enter:  target string 46.strnatcasecmp ():  Natural order method to compare string length,  case-insensitive invocation:  int strnatcasecmp   (string  $str 1 , string  $str2 ) string cutting and stitching: 47.chunk_split () &nbsp: Dividing a string into small chunks:  str chunk_split (str  $body [,int  $len [ ,str  $end]) Enter:  $body target string,  $len length,  $str insert terminator   output:  split strings 48.strtok ():  cut strings Call:  str strtok (str  $str, str  $token) Target string $str, $token for flag cutting returns the cut string 49.explode ():   Use a string to split another string for a flag call:  array explode (str  $sep, str  $str [,int  $limit]) Enter:   $SEP for,  $str the target string,  $limit returns the array contains the maximum number of elements   output:  the array formed after the string was segmented 50.implode ():  with join,   Connect array values to a character string called: string implode  (string  $glue  , array  $pieces   $glue default,  "is directly connected to the 51.SUBSTR ():  intercept string call: string substr  (string  $string    int  $start  [, int  $length  ] ) string lookup replacement: 52.str_replace ():  string substitution operation,  Case-sensitive call Mix str_replace (mix  $search, mix  $replace, mix  $subject [,int  &   $num) Enter the string that the:  $search look for,  $replace the replaced string,  $subject the lookup strings,  & $num   Output:  return the replaced result 53.str _ireplace ()   string substitution operation,  case-insensitive call: mix str_ireplace  (mix  $search  , mix   $replace  , mix  $subject  [, int  &  $count]) Enter the string that the:  $search find,   $replace substituted string,  $subject be searched for strings, & $num   Output:  returns the replacement result 54.substr_count ():  statistics a string,   The number of occurrences in another string calls: int substr_count  (string  $haystack  , string  $needle [,  int  $offset  = 0[, int  $length  ]] ) 55.substr_replace ():  A string in the replacement string is called: mixed substr_replace  by another string (mixed  $string, string  $replacement,  int  $start  [, int  $length  ] ) 56.similar_text ():  returns the number of two identical characters in a string call:  int similar_text (str  $str 1, str  $str 2) Enter:  Two comparison string output:  reshape,  same character number 57. STRRCHR ():  returns a string in theA string called: string strrchr  (string  $haystack  , mixed $) that the last occurrence of the position in another string begins at the end. needle ) 58.strstr ():  returns a string called: string strstr  (string  $str, from the beginning position in another string to the end  string  $needle  , bool  $before _needle ) 59.strchr ():  strstr () alias,  Returns a string call to the end of the first occurrence of a string in another string: string strstr  (string  $haystack  , mixed  $needle  [, bool  $before _needle = false ] ) 60.stristr ():  Returns a string that starts at the end of a string in another string, case-insensitive call: string stristr  (string  $haystack  , mixed   $needle  [, bool  $before _needle = false ] ) 61.strtr ():  Some characters in the conversion string call: string strtr  (string  $str  , string  $from  , string   $to  ) 62.strpos ():  looks for the first occurrence of a character in a string to call: int strpos  (string  $haystack    mixed  $needle  [, int  $offset  = 0 ] ) 63.stripos ():  find the position where a character appears first in a string,  case-insensitive   call:  int  stripos  (string  $haystack  , string  $needle  [, int  $offset  ]  ) 64.strrpos ():  looks for the last occurrence of a character in a string call: int strrpos  (string  $haystack  ,  string  $needle  [, int  $offset  = 0 ] ) 65.strripos ():  Looks for the last occurrence of a character in a string,  case-insensitive call: int strripos  (string  $haystack  , string $ needle [, int  $offset  ] ) 66.strspn ():  returns the substring length   invocation for the first time in the string that conforms to mask:  int  strspn  (string  $str 1 , string  $str 2 [, int  $start  [,  int  $length  ]] ) 67.strcspn ():  returns the length of a string that does not conform to mask in the string: int strcspn  (string   $STR 1 , string  $str 2 [, int  $start  [, int  $length  ]   Input:  $str 1 is queried,  $STR 2 query string, $start the character to start the query, $length is the query length   output:  returns from the start to the first few character string statistics: 68.str_word_count ():  The number of words contained in the statistic string is called:  mix str_word_count (str  $str,  []) Enter:  target string   output:  statistics number 69. strlen ():  statistic string length Int strlen (str  $str) input:  target string   Output:  integer length 70.count_chars ():  Statistics the number of occurrences of all letters in the string (0..255)   Call: mixed count_chars  (string  $string  [, int $ mode ] ) string encoding: 71.md5 ():  string MD5 encoding   ?   1 2   $str  =  "Hello"; ECHO&NBSP;MD5 ($STR);
Array function Array creation: 72.array (): Generate an array? 1 2 $a = array ("Dog", "Cat", "Horse"); Print_r ($a);
An array value or a key => value an array-type variable 73.array_combine (): Generates an array with the value of one array as the key and the other as the value $a 1 = Array ("A", "B", "C", "D"); $a 2 = Array ("Cat", "Dog", "Horse", "Cow"); Print_r (Array_combine ($a 1, $a 2));     $a 1 provides a key, $a 2 provides a composite array of 74.range (): Creates and returns an array containing the specified range of elements.      $number = range (0,50,10); Print_r ($number); Input: 0 is the minimum, 50 is the maximum, 10 is the step output: The composite array 75.compact (): Create an array of variables with the parameters? 1 2 3 4 5 6 $firstname = "Peter"; $lastname = "Griffin"; $age = "38"; $result = Compact ("FirstName", "LastName", "age");   Print_r ($result); A variable or array returns an array of variable names, the value of the variable, or a multidimensional array. will be recursively processed 76

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.