Share methods to improve PHP programming skills_PHP Tutorial

WBOY
Release: 2016-07-13 17:45:44
Original
735 people have browsed it

We already know a lot about PHP programming technology. It is recommended that you read this article, "PHP Experience Sharing: Commonly Used Tips" for your reference. Introduced below are several methods to improve PHP programming skills.
1. PHP tag
I know that some people like to use abbreviated tags when writing PHP code, but this is not a good habit, because abbreviated tags cannot be recognized correctly on some servers, and the use of standard PHP tags makes you Your PHP code can be compiled accurately on any server. PHP source code download down.phperz.com
2. Debugging of PHP code
Sometimes we encounter problems when running PHP code and we don't know where the problem lies. There is a special error_reporting() function in PHP, which can tell 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 on the second line of the file:
error_reporting(E_ALL);
3. Use comments
If your PHP code is 1,200 lines long, it can be difficult to figure out what it is doing. The way to solve this problem is to add comments to your code.
There are three ways to add comments in PHP: PHP Programmer Station
The following is the quoted content:
// Your comment //
# your comment
/*Your comment*/
?>
4. Indentation of PHP code

The following is the quoted content:
// Settings //
$var1 = "This";
// Showing Variables //
if($var1 == "This"){
echo"You said This";
}else{
echo"You said That";
www.phperz.com
}
?>
5. Correct your PHP file inclusion method
In PHP code, before including another file, it will first confirm that it exists, as in the following example: down.phperz.com
The following is the quoted content:
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 a connection to the database, and you may encounter some minor troubles. Most people who are prone to database problems write code in this form:
The following is the quoted content:
mysql_query("INSERT INTO tableName ('id','name') VALUES('1','Mike')");
?>
After running it, he found that the data was not inserted into the database. We can solve this problem like this: PHP Programmer Station
The following is the quoted content:
mysql_query("INSERT INTO tableName ('id','name') VALUES('1','Mike')")
or exit("MySQL Error : " . mysql_error());
?>
7. Abbreviate statements similar to IF-THEN
If you receive data from a registration page, and you want to ensure that all information is filled in, you might use statements that contain a lot of IF-THEN format, like this one:
The following is the quoted content:
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.");}
?>
And you can actually make it only one line by merging the IF-THEN statements of these two lines:
The following is the quoted content:
if((!$_POST[name]) || (!$_POST[email]))
{exit("Sorry, but you did not fill-in all of the requested fields.");}
?>
|| and OR, && and AND have the same meaning respectively.
8. Use echo or print?
Most people will say "echo and print are the same", and I agree with this point of view. However, echo runs much faster than print, and has one less letter than print. The echo command appeared later than print (I think so), so obviously you know what to choose.
9. Enter a large section of HTML from time to time
I believe many people have solutions to this problem, but I still want to tell you some solutions to this problem.
⑴. Enter the closing tag of PHP, and then you can enter the HTML code at will, and then the opening tag of PHP (I don’t like to do this because it looks very unprofessional).
⑵. Add a backslash to every sentence of HTML code (this is possible, but you have to do it all the time - every sentence).
⑶. Use the echo or print command, nothing more (recommended): PHP source code download down.phperz.com
The following is the quoted content:
// Showing a huge chunk of HTML at a time //
echo<< Large, Orange Text in Font Size 3



More HTML down here..



Centered text

END;
?>
I hope that the introduction of the above content can help you.

Author "Rain or shine"

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/478637.htmlTechArticleWe already know a lot about PHP programming technology. We recommend that you read this article, "PHP Experience Sharing: Commonly Used Tips" for your reference. Introduced below...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!