I have invented many PHP programmers, especially those who have not been learning for a long time and do not know the essence of PHP. How did Perl become famous in the business world? Its strong regular expression. What about PHP? He is a language developed from Unix, and of course it will continue.
I have invented many PHP programmers, especially those who have not been learning for a long time and do not know the essence of PHP. How did Perl become famous in the business world? Its strong regular expression. What about PHP? He is a language developed from Unix. of course, he has continued to have many features of Perl, and C has all its strengths. 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 exploitation techniques, PHP regular expressions, and PHP templates. later I will write a complete combination of PHP, COM, PHP, and XML.
1. techniques for using variables and arrays
(1) a few array functions are used by many people. Foreach, list, and each. Let's tell you a few examples. Example:
$ Data = array ('a' => 'data1', 'B' => 'data2 ', 'C' => 'data3 ');
While (list ($ subscript, $ value) = each ($ data ))
{
Echo '$ subscript => $ value ::';
Echo '$ subscript => $ value \ n
';
}
Reset ($ data );
Foreach ($ data as $ subscript => $ value)
{
Echo '$ subscript => $ value ::';
Echo '$ subscript => $ value \ n
';
}
(2) function variables, variable variables, and variable "pointer": See the following example:
// 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 ($ ){
$;
}
$ C = 0;
Function ($ c );
Echo $ c; // $ c is still 0
Function (& $ ){
$;
}
$ C = 0;
Echo $ c; // $ c is 1
?>
The reason why it is called "pointer" is that he has the same effect 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 title, and Perl's regular expressions are famous. PHP is not weak, and he continues the regular expression rules of Perl and has his own set of rules. Here we only talk about PHP regular expressions.
Regular expressions are the most basic elements. In short, it is a set of rules used to determine whether other elements comply with their own rules, or whether they have similar characteristics.
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, the regular expression is "^ 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 = '000000 ';
If (ereg ($ pattern, $ phone ))
Echo 'Call the number to Beijing ';
Else
Echo 'not the number to be sent to 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 complies with the rules at the same time. Regular expressions are widely used, such as the parsing of the so-called VBB code LBB code in the LBB and VBB forums.