1. 10 sentences
1. Don’t rely on the register_global=ON environment. From the day you just know how to configure the PHP operating environment and don’t even understand how register_global’s ON/OFF will affect you, you should bravely It is set to OFF.
2. Look at how to use error_reporting before writing a program.
3. If you don’t understand, it’s okay to ask yourself, but you need to check the manual before that.
4. Of course, you need to understand the user manual. When you can't find the answer in the manual, you should consider searching on the Internet.
5. After you have just learned php+mysql, don’t clamor to write a forum, write XXX. Understand that just because you have just learned to write Chinese characters does not mean that you are capable of writing poetry.
6. When learning web programming, you should first get to know your friend html.
7. After you have some ability, try to answer questions from novices. Don’t be complacent when you see that you understand something but others don’t. It’s even worse to leave without saying, “It’s simple, that’s a basic thing.”
8. Thinking is a good habit. If you don’t write, it means you have nothing.
9. Write a program. If you feel satisfied with it, read it again a week later. Maybe you will think it should be changed
10. When you have time, look at other people's programs and find out other people's shortcomings or Weigh the advantages yourself.
2. Take what you need
1. Be good at using "references", which can directly affect the efficiency of the program.
2. Being good at using ternary operators can make the program more streamlined and efficient.
For example:
PHP code:--------------------------------------------- -----------------------------------------------
if ($ data[$i]['nickname'])
{
$nickname = $data[$i]['nickname'];
}
else
{
$nickname = $data[$i]['ip'];
}
-------------------------- -------------------------------------------------- ---
can be written as:
PHP code:----------------------------- -------------------------------------------------- -
$nickname = $data[$i]['nickname'] ? $data[$i]['nickname'] : $data[$i]['ip'];
- -------------------------------------------------- -----------------------------
3. Good at organizing if...else... Loop
For example:
PHP code:---------------------------------- -----------------------------------------------
$ ext_name = strtolower(str_replace(".", "", strrchr($upfilename, ".")));
if (!empty($type))
{
if (!strpos($ type, $ext_name))
{
echo "Please upload the file of $type form.";
exit();
}
}
--- -------------------------------------------------- -----------------------------
You should write the above code like this:
PHP code: -------------------------------------------------- -------------------------------
$ext_name = strtolower(str_replace(".", "", strrchr($ upfilename, ".")));
if (!($type==='') && strpos($type, $ext_name)===false)
{
echo "Please upload the file of $type form.";
exit();
}
------------------------- -------------------------------------------------- -----
4. Try to make your code as clear as possible
If it is written like this, it will be a headache:
PHP code: --- -------------------------------------------------- --------------------------
$foo=$_post["foo"];
$username=$_post[ "user"];
$group=$_POST["group"];
if ($group=="wheel"){
$username=$username."wheel";
}
-------------------------------------------------- ------------------------------------
The same code, so it is easier People can see it comfortably:
PHP code: ---------------------------------- ---------------------------------------------
$foo = $_post["foo"];
$username = $_post["username"];
$group = $_POST["group"];
if ($group=="wheel")
{
$username = $username."wheel";
}
----------------------- -------------------------------------------------- -------
Of course, after you have a certain foundation, you should write it like this:
PHP code: --------------- -------------------------------------------------- ---------------
$foo = &$_POST['foo'];
$username = $_POST["group"]!='wheel' ? $ _POST["username"] : $_POST["username"].'wheel';
------------------------- -------------------------------------------------- -----
5. Write standardized mysql statements.
Field and table names are quoted with "`" to avoid the impact of reserved words.
If you see a sql query like the following, it will give you a headache:
PHP code:---------------------- -------------------------------------------------- --------
$query="select `flash_comment`.`content` , `flash_comment`.`nickname` , `flash_comment`.`date` , `flash_comment`.`ip` , `product `.`p_name` , `sgflash`.`fid` from `flash_comment` left join `product` on ( `flash_comment`.`p_no` = `product`.`p_no` ) left join `sgflash` on ( `product` .`p_name` = `sgflash`.`f_name` ) where `flash_comment`.`p_no` != '' order by `flash_comment`.`date`";
-------- -------------------------------------------------- -----------------------
The same query is much clearer when written like this:
PHP code:------------------------------------------------- ----------------------------------
$query = "Select `flash_comment`.`content` , `Flash_comment`.`nickName`, Flash_comment`.`date`,` Flash_comment`.`ip`, `pRODUCT`.`p_name`,` sgflash`.`Fid`
Flash_commxt`
left JOIN `product` ON ( `flash_comment`.`p_no` = `product`.`p_no` )
LEFT JOIN `sgflash` ON ( `product`.`p_name` = `sgflash`.`f_name` )
Where `flash_comment`.`p_no` != ''
orDER BY `flash_comment`.`date`";
---------------- -------------------------------------------------- -------------
//
.....