本菜鸟PHP基础薄弱,想咨询大家一下。我要是想自定义一个函数,比如说“check_file”。如何定义好呢?

解决方案 »

  1.   

    //当然也可以指定更多参数,用逗号号隔开
    function check_file($filename)
    {
       //函数体
       return true;
    }
      

  2.   

    谢谢您的回复,Fatal error: Call to undefined function check_file() in D:\wamp\www\install\index.php on line 89
    这个是我的程序报的错误,说是未定义 check_file函数,可我定义后还是显示错误。╮(╯▽╰)╭
    实在是想不出办法才到这里来的。最后还是谢谢您的回复吧!
      

  3.   

    必须将你定义的函数,放到index.php里,或者当做文件include或者require.
      

  4.   

    恩 我放在index.php里了  提示的错误里显示的那个路径
      

  5.   

    应该不会, 你
    <?php//index.php 内容$a = "c:/test.txt";check_file( $a );  //调用的时候 函数名不要写错了
    function check_file( $file )  // 在index.php结尾的地方加上..
    {   return true;
    }//这样应该在调用的时候就不会出错了
    ?>
      

  6.   

    您说的这个我明白了,可我这个程序不是一个小程序,把您这个加上别的代码也会出错的!/* 检查目录 */
        foreach ($dir as $val)
        {
            $tip = $val.$lang['dir'];
            $writable .= '<li><strong>'.$tip.'</strong>'.str_repeat('.', (80 - strlen($tip)));
            if(check_file(ROOT_PATH . $val) < 2)
            {        
                $writable .= '<span style="color: #C00000">'.$lang['cannt_write'].'</span>';
                $disabled  = ' disabled="true"';
            }
            else
            {
               $writable .= '<span style="color: green">'.$lang['can_write'].'</span>';
            }
            $writable .= '</li>';
        }
      

  7.   

    这里面就if(check_file(ROOT_PATH . $val) < 2)这行不对。
    /* 检查目录 */
        foreach ($dir as $val)
        {
            $tip = $val.$lang['dir'];
            $writable .= '<li><strong>'.$tip.'</strong>'.str_repeat('.', (80 - strlen($tip)));
            if(check_file(ROOT_PATH . $val) < 2)
            {        
                $writable .= '<span style="color: #C00000">'.$lang['cannt_write'].'</span>';
                $disabled  = ' disabled="true"';
            }
            else
            {
               $writable .= '<span style="color: green">'.$lang['can_write'].'</span>';
            }
            $writable .= '</li>';
        }