A few of the essentials that PHP programmers generally ignore

Source: Internet
Author: User
Tags foreach array ereg expression variables php and php regular expression variable
Program | The essence of the software I found that a lot of PHP programmers, especially the study is not very long, 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 under UNIX, and of course it inherits many of the features of Perl, and C has all the advantages. Fast, concise, clear, especially the C programmer, PHP is to love, I just love the "php" (Forgot girlfriend:)). Here, I want to write a PHP variables, array application techniques and PHP regular expression, PHP template application, and later have time to write PHP and COM, PHP and XML full integration.

1, variable, array of application techniques
(1) Many people use not much of the array function. foreach, list, each. Give a few examples, should be able to know. Cases:
<?php
$data = Array (' A ' => ' data1 ', ' B ' => ' data2 ', ' C ' => ' data3 ');
while (the list ($subscript, $value) = each ($data))
{
echo "$subscript => $value::";
echo "$subscript => $value \n<br>";
}

Reset ($data);
foreach ($data as $subscript => $value)
{
echo "$subscript => $value::";
echo "$subscript => $value \n<br>";
}
(2) The variable of the function, the variable of the variable, the "pointer" of the variable: look at the following example:
<?php
Variable for variables
$var = "This is a Var";
$varname = "Var";
echo $ $varname;
Variables for functions
function Fun1 ($STR) {
Echo $str;
}
$funname = "FUN1";
$funname ("This is a function!");
?>
The "pointer" of the variable. This pointer adds double quotes to indicate that he is not a real pointer. Look at the following example:
<?php
function ($a) {
$a + +;
}
$c = 0;
function ($c);
Echo $c; $c is still 0.
function (& $a) {
$a + +;
}
$c = 0;
Echo $c; $c is 1
?>
It is called "pointer" because he has the same function as the pointer in C language. But this is not really a pointer, can only be this to understand.

2, Regular expression
Regular expressions are a very big topic, and Perl's regular expressions are so powerful that they are famous. and PHP is not weak, he inherits Perl's regular expression rules, and his own set of rules. Here's just PHP's own regular expression.
Regular expressions are the most basic element. It is simply a set of rules that determine whether other elements conform to their own rules, or whether they have the same feature description.
The start of the regular expression: ^, end of $, between the two symbols is a matching element. If you check a phone number is not a number to Beijing, the regular expression is "^010$". As long as the first 3 area code is 010, is Beijing's number, the back of the phone number will not be the tube. Then, the regular expression matching function ereg is used to judge the example:
<?php
$pattern = "^010$";
$phone = "01080718828";
if (Ereg ($pattern, $phone))
echo "hit the number in Beijing";
Else
echo "is not the number of the hit Beijing";
?>
This is the regular expression. Beijing's telephone is 8 digits, then I want to know this number is correct? What if he presses the 9-digit number? What if the judgment is correct? This will use the character clusters of the regular expression. So the regular expression of the example above is written as follows: ^010[0-9]{8}$, you can also determine whether the number is in accordance with the rules. Regular expressions have many applications, such as LBB, VBB forum in the post of the so-called VBB Code LBB code parsing, are done with regular expressions.

3, Template
Knowing the function of the regular expression, you can know the template. What is a template? Give me an example? General writing Web pages used in the background program, are inserted in the Web page of the program code. such as PHP. This is the mix of HTML and PHP. The advantage is that the reading speed is fast, the disadvantage is that if we work together to do the site, then not programmers will not change the net.
And with the template, you can achieve the most rationalization of the division of labor. Art only do the page, the program only write backstage, and then together. Excellent JSP provides a custom label feature that completes the template function well. And the mainstream of PHP how to do it? is to use the regular expression to do. can go online to download a phplib, inside the PHP directory has a template.inc source code file, that is the use of PHP to implement the template application class.

Because of the limited space, here is simply to say that the content, if you really want to learn, but also to see a special textbook. You can write a small book if you want to be clear about regular expressions.


Related Article

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.