Some of the highlights that PHP developers can easily overlook

Source: Internet
Author: User
Tags foreach array ereg expression variables regular expression variable

Now found that 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? It's a powerful regular expression. And what about PHP? It is a language developed from under UNIX, and of course it inherits many of the features of Perl, while the advantages of C are: fast, concise, and clear.

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:

$data = Array (' A ' => ' data1′, ' B ' => ' data2′, ' C ' => ' data3′);

while (the 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) The variable of the function, the variable of the variable, the "pointer" of the variable: look at the following example:

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:

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:

$pattern = "^010$";

$phone = "01080718828″;

if (Ereg ($pattern, $phone))

echo "hit the number in Beijing";


echo "is not the number of the hit Beijing";


3, Template

Knowing the function of the regular expression, you can know the template. What is a template? for example, the General writing Web page 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 source code file, that is the use of PHP to implement the template application class.

Article from the PHP home,

Article Address:

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