About PHP programming Technology related knowledge, we have learned a lot, suggest you read this article, "PHP Experience sharing: Common Tips" for your reference. Here are a few ways to improve your PHP programming techniques.
1. PHP tags
I know that some people like to use a thumbnail tag when they write PHP code. , but this is not a good habit, because the thumbnail tag is not recognized correctly on some servers, and the use of standard PHP tags allows you to compile your PHP code exactly on any server. PHP Source Download down.phperz.com
2, the debugging of PHP code
Sometimes we run into problems running PHP code and we don't know where the problem is. and PHP has a error_reporting () function that tells you every error in your code. If you want it to display all possible error messages for the page, you can put the following code in the second line of the file:
Error_reporting (E_all);
3. Use annotations
If you have 1200 lines of PHP code, it is difficult to figure out what it is going to do, and the solution to this problem is to annotate your code.
There are three ways to add comments to PHP: PHP Programmer Station
The following is the referenced content:
Your comments//
# Your notes
/* Your comment */
?>
4, the PHP code indentation
The following is the referenced content:
Settings//
$var 1 = "this";
Showing Variables//
if ($var 1 = = "This") {
echo "You said this";
}else{
echo "you said that";
Www.phperz.com
}
?>
5, Fix your PHP file contains the way
PHP code that contains another file before it is determined to exist, as in the following example: down.phperz.com
The following is the referenced 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, you may encounter a little trouble, most people prone to database problems are in this form to write code:
The following is the referenced content:
mysql_query ("INSERT into tableName (' id ', ' name ') VALUES (' 1 ', ' Mike ')");
?>
After running he found that the data is not inserted into the database, we can solve this problem: PHP Programmer station
The following is the referenced content:
mysql_query ("INSERT into tableName (' id ', ' name ') VALUES (' 1 ', ' Mike ')")
or exit ("MySQL Error:".) Mysql_error ());
?>
7, abbreviations similar to if-then statements
If you receive data from a registration page and you want to make sure that all the information is filled in, you might use a statement that contains many if-then formats, like this:
The following is the referenced content:
if (!$_post[name]) {exit ("Sorry, but do not have fill-in all of the requested fields.");}
if (!$_post[email]) {exit ("Sorry, but do not have fill-in all of the requested fields.");}
?>
Instead, you can actually merge the two lines by merging the If-then statement to make it only one line:
The following is the referenced content:
if ((!$_post[name)) | | (!$_post[email]))
{Exit ("Sorry, but do not fill-in all of the requested fields.");
?>
|| and or,&& and and each have the same meaning.
8. Use Echo or print?
Most people will say "Echo and print are the same", and I agree with this view. However, echo runs much faster than print and one letter less than print. The echo command appears later than print (I think), and obviously you know how to choose.
9. Enter a large section of HTML language
I believe a lot of people have a solution to this, but I still want to talk to you about some ways to solve this.
⑴, enter the end tag of the PHP, then you can enter the HTML code at will, then the PHP start tag (I do not like this, because it looks very unprofessional).
⑵, add backslashes in every HTML code (this is possible, but you always have to--every sentence).
⑶, using the Echo or Print command, that's all (recommended): PHP source code Download down.phperz.com
The following is the referenced 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;
?>
Hope that through the above content of the introduction, can bring you help.
Author "Rain or Shine"
http://www.bkjia.com/PHPjc/478637.html www.bkjia.com true http://www.bkjia.com/PHPjc/478637.html techarticle about PHP Programming technology related knowledge, we have learned a lot, suggest you read this article, "PHP Experience sharing: Common Tips" for your reference. The following are ...