How to improve PHP programming technology

Source: Internet
Author: User
Tags echo command
We have learned a lot about PHP programming technology. I suggest you read this article, "PHP experience sharing: common tips" for your reference. The following describes several methods to improve PHP programming technology. 1. PHP labels I know some people like to use .. SyntaxHighlighter. all () when writing PHP code ();

We have learned a lot about PHP programming technology. I suggest you read this article, "PHP experience sharing: common tips" for your reference. The following describes several methods to improve PHP programming technology.
1. PHP labels
I know some people prefer to use scaling labels when writing PHP code. But this is not a good habit, because scaling labels cannot be correctly identified on some servers, the use of standard PHP labels allows you to accurately compile your PHP code on any server. Download down.phperz.com from PHP source code
2. PHP code debugging
Sometimes we encounter problems when running PHP code, and we don't know where the problem is. In PHP, there is an error_reporting () function, which tells you every error in your code. If you want it to display all possible error messages on the page, you can put the following code in the second line of the file:
Error_reporting (E_ALL );
3. Use annotations
If your PHP code contains 1200 lines, it is very difficult to understand what it is to do. The solution to this problem is to add comments to your code.
There are three methods to add a comment in PHP: PHP programmer site
Reference content is as follows:
// Your comment //
# Your comment
/* Your comment */
?>
4. PHP code indentation

Reference content is as follows:
// Settings //
$ Var1 = "This ";
// Showing Variables //
If ($ var1 = "This "){
Echo "You said This ";
} Else {
Echo "You said That ";
Www.phperz.com
}
?>
5. modify the php file inclusion method.
Before the PHP code contains another file, it is determined that it exists, for example: down.phperz.com
Reference content is as follows:
If (! File_exists ("layout. inc. php") {exit ("Error: LayOut File Missing ");}
Else {include_once ("layout. inc. php ");}
?>
6. database query
Sometimes your PHP code contains database connections, and you may encounter some minor troubles. most people who are prone to database problems write code in this form:
Reference content is as follows:
Mysql_query ("insert into tableName ('id', 'name') VALUES ('1', 'Mike ')");
?>
After running, he found that the data was not inserted into the database. we can solve this problem as follows: PHP programmer site
Reference content is as follows:
Mysql_query ("insert into tableName ('id', 'name') VALUES ('1', 'Mike ')")
Or exit ("MySQL Error:". mysql_error ());
?>
7. scale down statements similar to IF-THEN
IF you want to ensure that all the information has been filled in, you may use statements that contain many IF-THEN formats, as shown below:
Reference content is as follows:
If (! $ _ POST [name]) {exit ("Sorry, but you did not fill-in all of the requested fields .");}
If (! $ _ POST [email]) {exit ("Sorry, but you did not fill-in all of the requested fields .");}
?>
In fact, you can merge the IF-THEN statements of the two rows to make it only have one row:
Reference content is as follows:
If ((! $ _ POST [name]) | (! $ _ POST [email])
{Exit ("Sorry, but you did not fill-in all of the requested fields .");}
?>
| And or, & AND have the same meaning.
8. use echo or print?
Most people will say "echo and print are the same". I agree with this. However, echo runs much faster than print and has one letter less than print. The echo command appears a little later than print (I think so). Obviously, you know how to choose it.
9. enter a large HTML language from time to time
I believe many people have a solution to this problem, but I still want to talk about some solutions.
(1) enter the end tag of PHP, and then enter the HTML code at will, and then the start tag of PHP (I don't like this because it looks unprofessional ).
(2) add a backslash to each HTML code (this is feasible, but you always have to do this-every sentence is required ).
(3) use the echo or print command. (recommended) download down.phperz.com from the PHP source code.
Reference content is as follows:
// Showing a huge chunk of HTML at a time //
Echo < Large, Orange Text in Font Size 3



More HTML down here ..



Centered text
END;
?>
We hope that the above content will help you.

Author: "No Rain or Shine"

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.