background image

3.善于组织 if...else...回圈
比如

:

PHP 代码:
$ext_name=strtolower(str_replace(".","",strrchr($upfilename,".")));
if(!empty($type))
{
    if(!strpos($type,$ext_name))
    {
        echo"Pleaseuploadthefileof$typeform.";
        exit();
    }
}

上面的代码你应该写成这样

:

PHP 代码:
$ext_name=strtolower(str_replace(".","",strrchr($upfilename,".")));
if(!($type==='')&&strpos($type,$ext_name)===false)
{
    echo"Pleaseuploadthefileof$typeform.";
    exit();
}

4.尽量让你的代码清淅些
如果写成这样,是比较让人头痛的

:

PHP 代码:
$foo=$_post["foo"];
   $username=$_post["user"];
$group=$_POST["group"];
if($group=="wheel"){
$username=$username."wheel";
}

同样的代码,这样就比较让人看得舒服了

:

PHP 代码:
$foo      =$_post["foo"];
$username=$_post["username"];
$group    =$_POST["group"];
if($group=="wheel")
{
    $username=$username."wheel";
}

当然,有一定基础后,你应该要写成这样

: