$sub = "bbs.it-home.org";
$PTN = '/\w*\.\w*\.\w*/';
Regular expressions, meta-data, returned data
- Preg_match ($PTN, $sub, $mats);
echo " "; - Print_r ($mats);
- echo "
";
- ?>
- Matching IP
- $STR = "My IP is 192.168.10.1sdjlfajdf192.178.39.4la";
$PTN = '/\d+\.\d+\.\d+\.\d+/';
- Preg_match_all ($PTN, $str, $mats);
echo " "; - Print_r ($mats);
- echo "
";
?>
Copy CodePattern modifier, placed on the last side of the regular expression I,m,s,u,ei: Ignore case m: treated as multiple lines s: treated as one line u: Greedy mode, max mode e: Replace, can be processed by function, used to match the first parenthesis in a regular expression
- $STR = "Linux and PHP are lamp or Linux is very much";
- $PTN = '/linux/i ';
- Preg_match_all ($PTN, $str, $mats);
- echo "
"; - Print_r ($mats);
- echo "
";
- ?>
Copy Codem example m as multiple lines
- $str = "Linux and PHP are lamp or \nlinux is very much";
- $PTN = '/^linux/im ';
- Preg_match_all ($PTN, $str, $mats);
- echo "
"; - Print_r ($mats);
- echo "
";
- ?>
Copy Codepattern modifier
- $str = "Linux and PHP are lamp or \nlinux is very much";
- $PTN = '/.*/s ';
- Preg_match_all ($PTN, $str, $mats);
- echo "
"; - Print_r ($mats);
- echo "
";
- ?>
Copy CodeUse of E
- $STR = "123 php";
- $PTN = '/\d+\s (\w+)/E ';
- $rep = ' Strtoupper ';
- Preg_match_all ($PTN, $str, $mats);
- $str 2 = preg_replace ($PTN, $rep, $STR);
- echo "
"; - Print_r ($str 2);
- echo "
";
- ?>
Copy CodeBackward reference
- $STR = "123 php";
- $PTN = '/(\d+) (\s) (\w+)/';
- $rep = ' $3$2$1 ';
- Preg_match_all ($PTN, $str, $mats);
- $str 2 = preg_replace ($PTN, $rep, $STR);
- echo "
"; - Print_r ($str 2);
- echo "
";
- ?>
Copy CodeFive common functions 1. Match and replace string Preg_match ();p reg_match_all ();p reg_grep (); Search 2. String substitution preg_replace (); 3. String segmentation preg_split (); eval allows a string expression to execute a Preg_grep instance and do a search:
- such as the Representative article
- $arr = Array (
- "PHP html",
- "Linux Redhat Rhce",
- "Junzaivip test PHP",
- );
- What you need to search for
- $PTN = '/junzaivip/';
- Go back to what you searched for
- $arr 2 = Preg_grep ($PTN, $arr);
- echo "
"; - Print_r ($arr 2);
- echo "
";
- ?>
Copy Code4. Mathematical function 1.max (); 2.min (); Note: 1. Multiple numbers, 2, arrays of multiple numbers
- echo Max (3,45,6,7);
- echo "
";
- echo Max (Array (4,6,8,9));
- ?>
Copy Code5. Date function 1.time (); 2.date (); Convert the timestamp to date 3.strtotime ();//convert date to timestamp 4.microtime ();
- Calc Open Calculator
- Point of Origin of time:
- echo Time ();
- echo "";
- echo Date ("y-m-d h:i-s w T", 0);
- ?>
Copy CodeTime conversion to timestamp
- Cho strtotime ("2014-12-12");
- ?>
Copy CodeCalculate the exact date of the current time:
- echo Date ("Y-m-d h:i:s", Time () +8*3600);
- ?>
Copy CodeTo find the current date by modifying the time zone:
- Set China's time zone as the default time zone
- Date_default_timezone_set ("PRC");
- echo Date ("Y-m-d h:i:s", Time ());
- ?>
Copy CodeNote: If each change is more troublesome, go directly to modify the PHP configuration file php.ini file, directly modify the inside of the date to see TimeZone modified to Prcdate parameters: Y 2014 full y 14 years only after two M March has a leading 0n March no leading 0d 05 Date has a leading 0j 5th period no leading 0H 24 h 12 h i 05 min s 05 sec w 0-6 Sunday to Saturday t 311 months how many days L is a leap year//How to distinguish the level is divisible by 4, and if it can be divisible by 100, then it must be divisible by 400, at this time it is a leap year
Set China's time zone as the default time zone
- Date_default_timezone_set ("PRC");
- $y = "1900/1/1";
- $time = Strtotime ($y);
echo Date ("L", $time);
- ?>
Copy CodeMicrotime () μs Calculate the run time of the script:
- $stime = Microtime (1);//Note This position must be true, no one can participate in the calculation
- Sleep (1);
- $etime = Microtime (1);
- Echo $etime-$stime;
- ?>
Copy CodeExample: Vannen Calendar Technical point 1. A few months and a few days 2. Sunday to Saturday No. 3.1 is the day of the Week 4. How many days are there in 5. Next year and previous year 6. Next month and last month perpetual calendar code:
Modify character encoding
- Header ("Content-type:text/html;charset=utf-8");
- Date_default_timezone_set ("PRC");
- Get when the year before
- $year = $_get[' y ']?$_get[' y ']:d ate (' Y ');
- Get Current Month
- $month = $_get[' m ']?$_get[' m ':d ate (' m ');
- Gets the number of days that the current month is getting
- $days = date (' t ', Strtotime ("{$year}-{$month}-1"));//must be enclosed in double quotes
- The current number is a few weeks
- $weeks = Date (' W ', Strtotime ("{$year}-{$month}-1"));
- All have content centered
- echo " ";
- Output table Header
- echo "
{$year} year {$month} month ";
- Output Date Table
- echo "
- Output First line
- Table header cells are created by th
- echo "
- echo "
- echo "
- echo "
- echo "
- echo "
- echo "
- Start Shop Form
- for ($j =0; $j < 7; $j + +) {
- } else{
- }
- }
- echo "
- echo "
- for ($i = 1-$weeks; $i <= $days;) {
- echo "
- if ($i > $days | | $i < 1) {
- echo "
- echo "
- $i + +;
- }
- echo "
echo "
";
";
Day | ";
one | ";
two | ";
three | ";
four | ";
five | ";
six | ";
";
";
| ";
{$i} | ";
";
";
- Realize last year and last month
- if ($month = = 1) {
- $prevyear = $year-1;
- $prevmonth = 12;
- } else{
- $prevyear = $year;
- $prevmonth = $month-1;
- }
- if ($month = = 12) {
- $nextyear = $year + 1;
- $nextmonth = 1;
- } else{
- $nextyear = $year;
- $nextmonth = $month + 1;
- }
Output buttons for the last month and next January
- echo "
Last month | next month ";
- echo "
";
- ?>
Copy CodeError handling in PHP 1. Closing and opening error 2. Bug report level 3. Error Reporting Place 1), turn off and turn on Error e_alle_error//Critical Error e_warning//Warning error e_parse//syntax error E_notice//Prompt error 2), off error Display_error = off what level of fault: error_reporting = e_allerror_reporting = E_all & ~e_notice//Report all errors, but in addition to prompting for errors3), Error Place: Whether to error from the browser Display_error = off//whether to output errors to a custom log file Log_errors = Onerror_log = D:\phplogs\php.log |