About PHP Template Application Tips Summary _php Tutorial

Source: Internet
Author: User
Tags ereg perl regular expression php regular expression php template
PHP after a long period of development, a lot of users are very familiar with PHP, here I publish a personal understanding, and discuss with you. I found a lot of PHP programmers, especially learning is not a long time, do not know the essence of PHP. How did Perl become famous in the business world? Its powerful regular expression. And what about PHP? He is a language developed from the UNIX, of course, has inherited many features of Perl, while the advantages of C have.

Here, I would like to write a PHP variable, array application techniques and PHP regular expression, PHP template application, later time to write PHP and COM, PHP and XML fully integrated.

1. PHP templates

Knowing the function of the regular expression, you can know the template. What is a php template? Give me an example? Generally write a Web page to use in the background program, are inserted in the Web page program code. such as PHP. This is the mix of HTML and PHP. This is the advantage of fast reading speed, the disadvantage is that if we work together to do the site, then non-programmers will not change the network. and using the template, you can achieve the most rationalization of division of labor. The art only makes the page, the program only writes the backstage, then then together. The excellent JSP provides a custom label function that completes the template function well. And how does the mainstream PHP do it? is to use regular expressions to do that. can go to the Internet to download a phplib, inside the PHP directory has a template.inc source code file, that is, with P

2. Application techniques of variables and arrays

(1) A lot of people do not use many array functions. foreach, list, each. To give a few examples, we should be able to know. Cases:

 
 
  1. php
  2. $ Data = Array (' a ' => ' data1 ', ' b ' => ' data2 ', ' c ' => ' Data3 ');
  3. while (list ($subscript, $value) = each ($data))
  4. {
  5. echo "$ Subscript = > $value:: ";
  6. echo "$ Subscript = > $valuen <br> ";
  7. }
  8. Reset ($data);
  9. foreach ($data as $subscript => $value)
  10. {
  11. echo "$ Subscript = > $value:: ";
  12. echo "$ Subscript = > $valuen <br> ";
  13. }

(2) Variables of the function, variables of variables, "pointers" to variables: see the following example:

 
 
  1. php
  2. Variables of variable
  3. $ var = "This is a var" ;
  4. $ varname = "var" ;
  5. echo $ $varname;
  6. Variables of the function
  7. function Fun1 ($STR) {
  8. Echo $str;
  9. }
  10. $ Funname = "Fun1" ;
  11. $funname ("This is a function!");
  12. ?>

The "pointer" of the variable. This pointer adds double quotes, indicating that he is not a real pointer. Take a look at the following example:

 
  
  
  1. !--? php
  2. function ($a) {
  3. $a + +;
  4. }
  5. $ c = 0 ;
  6. function ($c);
  7. echo $c;//$c still 0
  8. function (& $a) {
  9. $a + +;
  10. }
  11. $ c = 0 ;
  12. echo $c;//$c is 1
  13. ?

It is called "pointer" because he has the same function as the pointer in C language. But this is not the real pointer, only can be this to understand.

3. Regular expressions

Regular expressions are a very large topic, and the power of Perl's regular expressions is famous. and PHP is not weak, he inherited the Perl regular expression law, and his own set of rules. This is just about PHP's own regular expression. Regular expressions are the most basic element. In short, it is a set of rules for determining whether other elements are in accordance with their own rules, or whether they have the same feature description. The starting character of the regular expression: ^, end character $, between the two symbols is a matching element. If you check whether a phone number is called to Beijing, the regular expression means "^010$". As long as the first 3 digits of the area code is 010, is the number of Beijing, the phone number on the back of the tube. Then, use the regular expression matching function ereg to judge, for example:

 
  
  
  1. Php
  2. $ pattern "^010$";
  3. $ Phone "01080718828";
  4. if (Ereg ($pattern, $phone))
  5. echo "number to Beijing";
  6. Else
  7. echo "is not a number to Beijing";
  8. ?>

This is the regular expression. The telephone in Beijing is 8 digits, then I need to know if this number is correct? What if he presses the 9-digit number? What if it's wrong? This will use the regular expression of the character cluster. So the regular expression in the example above is written like this: ^010[0-9]{8}$, you can also judge whether the number is in accordance with the rules. Regular expressions have a lot of applications, like the LBB, VBB forum in the post of the so-called VBB Code LBB Code of the resolution, are used regular expression to complete.


http://www.bkjia.com/PHPjc/446446.html www.bkjia.com true http://www.bkjia.com/PHPjc/446446.html techarticle PHP After a long period of development, a lot of users are very familiar with PHP, here I publish a personal understanding, and discuss with you. I found a lot of PHP programmers, especially learning is not very ...

  • 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.