Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the key points of using PHP?

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article will explain in detail what are the main points about the skills of using PHP, and the content of the article is of high quality, so the editor will share it with you for reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.

Programmers are still making continuous progress in learning the PHP language. We should constantly accumulate experience in the actual code writing to improve our coding program. Below we will introduce several PHP use skills for your reference.

How did Perl become famous in the business world? Its powerful regular expressions. And PHP? It is a language developed from Unix, of course, it inherits many of the features of Perl, while C has its advantages. Fast, concise and clear, especially C programmers, PHP is my favorite, I just love "PHP" (I forgot my girlfriend:). Here, I want to write an article on PHP variables, array application skills and PHP regular expressions, PHP template application, and then have time to write the complete combination of PHP and COM, PHP and XML.

PHP usage skills 1. Application skills of variables and arrays

(1) an array function that is not used by many people. Foreach 、 list 、 each . If you give a few examples, you should be able to know. Example:

< ?php $data = array('a' =>

'data1',' b' > 'data2',' c'= > 'data3'); while (list ($subscript, $value) = each ($data)) {echo "$subscript = > $value::; echo" $subscript = > $value

< br>

";} reset ($data); foreach ($data as $subscript = > $value) {echo" $subscript = > $value::; echo "$subscript = > $value

< br>

";}

(2) variable of function, variable of variable, "pointer" of variable: see the following example:

< ?php //变量的变量 $var = "this is a var"; $varname = "var"; echo $$varname; //函数的变量 function fun1($str) { echo $str; } $funname = "fun1"; $funname("This is a function !"); ?>

The pointer to the variable. The pointer is enclosed in double quotation marks, indicating that it is not a real pointer. Look at the following example:

< ?php function($a) { $a ++; } $c = 0; function($c); echo $c; //$c仍为0 function(&$a) { $a ++; } $c = 0; echo $c; //$c为1 ?>

It is called "pointer" because it has the same function as pointer in C language. But this is not a real pointer, it can only be understood in this way.

PHP usage tips 2. Regular expressions

Regular expressions are a very big problem, and Perl's regular expressions are famous for their power. And PHP is not weak, he inherited Perl's regular expression law, as well as his own set of rules. Here we only talk about PHP's own regular expressions.

Regular expressions are the most basic elements. To put it simply, it is a set of rules that are used to determine whether other elements conform to their own rules, or whether they have the same feature description.

The regular expression begins with ^ and ends with $, with matching elements between the two symbols. If you check whether a phone number is for Beijing, use a regular expression to express it as "^ 010 $". As long as the area code of the first three digits is 010, it is the number of Beijing, and the phone number behind it will be ignored. Then, use the regular expression matching function ereg to judge, for example:

< ?php $pattern = "^010$"; $phone = "01080718828"; if(ereg($pattern, $phone)) echo "打往北京的号"; else echo "不是打往北京的号"; ?>

This is the regular expression. All the phone calls in Beijing are 8 digits, so I need to know if this number is correct? What if he presses nine digits? If you judge right or wrong? This requires the character cluster of regular expressions. Then the regular expression of the above example should be written like this: ^ 010 [0-9] {8} $, you can also determine whether the number conforms to the rule. There are many applications of regular expressions, such as LBB, VBB Forum in the post of the so-called VBB code LBB code parsing, are done with regular expressions.

Tips for using PHP 3. Template

Now that you know what regular expressions do, you can know the template. What is a template? Can you give me an example? Generally speaking, when a background program is used to write a web page, the program code is inserted into the web page. Such as PHP. This is a mix of HTML and PHP. The advantage is that the reading speed is fast, and the disadvantage is that if we work together to do the website, then non-programmers will not change the network.

With templates, the most rational division of labor can be achieved. The artist only does the page, the program only writes the background, and then comes back together. Excellent Jsp provides the function of custom tags and completes the template function very well. And how does the mainstream PHP do that? Is to use regular expressions to do this. You can download a PHPLIB from the Internet, in which there is a template.inc source code file in the PHP directory, that is, the class used to implement the template with PHP.

What are the main points about the use of PHP skills to share here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report