PHP programmers should not ignore the three points, php programmers should not _ PHP Tutorial

Source: Internet
Author: User
Tags ereg php programming language php template
PHP programmers should not ignore the three points, and php programmers should not. PHP programmers should not ignore the three points. php programmers should not recently find many PHP programmers, especially those who have not studied for a long time, and do not know the essence of PHP. How can Perl be ignored by PHP programmers in the past?

Recently, 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. of course, he inherits many features of Perl and has advantages in C. It is fast, concise, and clear, especially for C Programmers. PHP is a favorite. Here, I want to write a PHP variable, array application technique, PHP regular expression, and PHP template application.
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 "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 ($ a) {$ 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 "call to Beijing "; else echo "not the number 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 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.

The above are some experiences and are very practical. The purpose is to allow everyone to better master the php programming language and hope everyone can gain something.

Parse recently found that many PHP programmers, especially those who have not studied PHP for a long time, do not know the essence of PHP. How did Perl...

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.