1. Functions of random numbers and times
echo rand (); Random number generator
echo rand (0,10); Random number Generation Range
echo Time (); Take the current timestamp
echo Date ("y-m-d h:i:s"); Format time
Strtotime ("2013-03-04 01:35:06"); Date Time converted to timestamp
2. About String Classes
$str = "Hello World";
echo strlen ($STR); Take string length
Var_dump (strcmp ($str, "Hello World"); Comparison of two strings
echo Strtolower ($STR); Turn lowercase
echo Strtoupper ($STR); Turn capital
Splits a string, returns an array
$str = "Hello|world|ni|hao";
Var_dump (Explode ("|", $str));
Stitching array elements into a single string
$attr =array ("AA", "BB", "CC", "DD");
Echo Implode ("--", $attr);
Replaces a string at the specified position
Echo Substr_replace ($STR, "* * *", 0,5); The first one in parentheses is the string to be manipulated, the second is what to replace in the future, the third is the start position, and the fourth one is the length
echo str_replace ("|", "* * *", $STR); Find replacements
Echo substr ($str, 0,5); Intercept string
3. Regular expressions
Number replaced by #
$str = "2hello 5li 6lei";
Echo preg_replace ("/\d/", "#", $str);
Split
Var_dump (Preg_split ("/\d/", $str));
Match the first string that satisfies a regular
Preg_match ("/\d/", $str, $arr);
Var_dump ($arr);
Match all strings that satisfy the regular
Preg_match_all ("/\d/", $str, $arr);
Var_dump ($arr);
4. Array methods
Determine if a value is inside an array
$attr =array (1,2,3,4,5,1);
Var_dump (In_array (2, $attr));
Flipping an array
Var_dump (In_reverse ($attr));
Take array length
echo count ($att);
Go heavy
Var_dump (Array_unique ($attr));
To delete an array element
Unset ($attr [1]);
Re-index
Var_dump (Drray_values ($attr));
Merging arrays
Var_dump (Array_merge ($attr, Array (5,6)));
To add an element to the array, return the index
Array_push ($attr, "Hello");
Example:
$attr =array (
Array ("Noo1", "Han"),
Array ("Noo2", "Hui"),
Array ("Noo2", "Uighur clan")
);
Use the drop-down list to display
echo "<select>";
foreach ($attr as $v)
{
echo "<option>{$v [1]}</option>";
}
echo "</select>";
PHP Common functions