I would like to give examples of the essence and skills in PHP language, and read examples of the essence and skills in PHP language. many PHP programmers, especially those who have not studied PHP for a long time, do not know the essence of PHP. How did Perl become famous in the business world? Its powerful regular expression. What about PHP? He is a language developed from Unix, and of course inherits many features of Perl. at the same time, C's "> <LINKhref =" http: // ww
Many PHP programmers, especially those who have not been learning for a long time, do not know the essence of PHP. How did Perl become famous in the business world? Its powerful regular expression. What about PHP? He is a language developed from Unix. of course, he inherits many features of Perl and has advantages in C. Fast, concise, and clear. especially for C programmers, PHP is a favorite. I love PHP very much (I forgot my girlfriend ). Here, I want to write an article about PHP variables, array application skills, PHP regular expressions, and PHP template applications. I will try again later to write the full combination of PHP, COM, PHP, and XML.
1. Application techniques of variables and arrays
(1) a lot of array functions are rarely used. Foreach, list, and each. Here are a few examples. Example:
$ Data = array ('a' => 'data1', 'B' => 'data2 ', 'C' => 'data3 ');
While (list ($ subscript, $ value) = each ($ data ))
{
Echo "$ subscript => $ value ::";
Echo "$ subscript => $ valuen
";
}
Reset ($ data );
Foreach ($ data as $ subscript => $ value)
{
Echo "$ subscript => $ value ::";
Echo "$ subscript => $ valuen
";
}
(2) function variables, variable variables, and variable "pointers ":
// Variable
$ Var = "this is a var ";
$ Varname = "var ";
Echo $ varname;
// Function variable
Function fun1 ($ str ){
Echo $ str;
}
$ Funname = "fun1 ";
$ Funname ("This is a function! ");
?>
The "pointer" of the variable ". This pointer is enclosed in double quotes, indicating that it is not a real pointer. Take a look at the following example:
Function ($ ){
$ A ++;
}
$ C = 0;
Function ($ c );
Echo $ c; // $ c is still 0
Function (& $ ){
$ A ++;
}
$ C = 0;
Echo $ c; // $ c is 1
?>
It is called "pointer" because it has the same function as the pointer in C language. But this is not a real pointer. it can only be understood in this way.
2. Regular expression
Regular expressions are a very big question. Perl's regular expressions are powerful and famous. PHP is not weak. it inherits the regular expression rules of Perl and has its own set of rules. Here we only talk about PHP regular expressions.
Regular expressions are the most basic elements. Simply put, it is a set of rules used to determine whether other elements comply with their own rules, or whether they have the same feature description.
The starting character of the regular expression: ^, ending Character $. The two symbols are matched elements. If you check whether a phone number is sent to Beijing, use a regular expression to indicate "^ 010 $ ". As long as the first three area codes are 010, that is, the Beijing Number, the phone number at the end will be no longer needed. Then, use the regular expression to match the ereg function. for example:
$ Pattern = "^ 010 $ ";
$ Phone = "01080718828 ";
If (ereg ($ pattern, $ phone ))
Echo "number to Beijing ";
Else
Echo "not the number for Beijing ";
?>
This is a regular expression. The numbers in Beijing are 8 digits. Do I need to know if this number is correct? What if he presses the 9-digit number? If it is true or false? This requires the use of regular expressions in character clusters. In the above example, the regular expression should be written as follows: ^ 010 [0-9] {8} $ to determine whether the number meets the rules at the same time. Regular expressions have many applications, such as the parsing of the so-called VBB code LBB code in the LBB and VBB forums.
3. Template
Now that you know the regular expression function, you can know the template. What is a template? For example? When a webpage is used as a background program, the program code is inserted into the webpage. Such as PHP. This is the hybrid writing of HTML and PHP. This advantage is that the reading speed is fast, and the disadvantage is that if you work together to build a website, non-programmers will not change the network.
With templates, the most reasonable division of labor can be achieved. The artist only serves as the page, and the program only writes to the background, and then combines them. Excellent Jsp provides the custom tag function to complete the template function. How does the mainstream PHP achieve this? This is done using regular expressions. You can download a PHPLIB file from the internet. The PHP directory contains a source code file of template. inc, which is the class used to implement template application using PHP.