+ -
当前位置:首页 → 问答吧 → 全部的答案!!

全部的答案!!

时间:2008-10-14

来源:互联网


第一题
<?php
/**
* loop_dir()
*
* @param string $dir
* @return void
*/
function loop_dir($dir) {
    if(is_dir($dir)) {
        $dir = realpath($dir);
        $dp = opendir($dir);
        while(($file = readdir($dp)) !== false) {
            if(is_dir($dir.'/'.$file) && $file != '.' && $file != '..') {
                loop_dir($dir.'/'.$file);
            } elseif($file != '.' && $file != '..') {
                echo $dir . DIRECTORY_SEPARATOR . $file . '<br/>';
            }
        }
        closedir($dp);
    } else {
        die($dir.' is not a dir');
    }
}


[php]
第二题
/**
* checkEmail()
*
* @param string $email
* @return boolean
*/
function checkEmail($email) {
    if(!preg_match('/^([0-9A-Za-z_]+)@([0-9A-Za-z_]+)\.(\w{2,})$/', $email))    {//检测邮箱是否正确
      die('The email address format is not correct.');
    }
    $cannot = array('sina.com','263.com','126.com','qq.com');
    $pos = strpos($email,'@');
    $pop3 = strtolower(substr($email,$pos + 1,strlen($email)));
    $username = substr($email, 0, $pos);
    $pop3name = explode('.', $pop3);
    $pop3name = $pop3name[0];
   
    //检测是否使用sina、263、126、163、QQ的邮箱
    if(in_array($pop3,$cannot)) {
        die('"' . $pop3 . '"' . ' can not use.');
    }
    //end
   
    //检测邮箱用户名和邮箱服务器名是否全部为数字。
    if((string)(int)$username === (string)$username || (string)(int)$pop3name === (string)$pop3name) {
        die('Username or pop3 name can not all number.');
    }
    //end
   
    //检测邮箱地址是否重复
    //email地址保存在test数据库的email表中,字段名为email_addr
    $db = mysql_connect('localhost','root','test');
    mysql_select_db('test',$db);
    $result = mysql_query("select id from email where email_addr='{$email}'",$db);
    if(mysql_num_rows($result) > 0) {
        die('The eamil had use.');
    }
    mysql_free_result($result);
    mysql_close($db);
    //end
   
    return true;
}
[/php]

[php]
第三题
/**
* add_date()
*
* @param string $date
* @param int $add 为增加天数,负数为减少天数
* @return string
*/
function add_date($date, $add) {
  //一定要输入格式为:1900-09-01的格式
  if(!preg_match("/^[0-9]{4}\\-[0-9]{2}\\-[0-9]{2}$/",$date)) {
    return false;
  }
    $timestamp = strtotime($date);
    if((string)(int)$add !== (string)$add) {
        die('增加的天数必须为整数.');
    }
    if($timestamp == false || $timestamp == -1 || $timestamp == 0) {
        die('日期格式错误.');
    }
    return date('Y-m-d',$timestamp + $add * 86400);
}
[/php]


第四题
$sql = "SELECT * FROM `topic` AS tp, `user` AS ue, `rank` AS rn
WHERE tp.belongid = 5 AND
rn.edit = 1 AND
rn.id = ue.rankid AND
ue.id = tp.userid";



第五题
/**
* slashesGPC()
*
* @return Array
* 返回一个由$_POST $_GET $_COOKIE转义之后组成的数组
*/
function slashesGPC() {
    $GPC = array_merge_recursive($_GET,$_POST,$_COOKIE);
  if (!get_magic_quotes_gpc()) {
    function addslashes_deep($value)
    {
        $value = is_array($value) ? array_map('addslashes_deep', $value) : addslashes($value);
        return $value;
    }
    $GPC = addslashes_deep($GPC);
    return $GPC;
  } else {
    return $GPC;
  }
}
?>


作者: liexusong   发布时间: 2008-10-14

格式很工整

作者: PHPChina   发布时间: 2008-10-15

还可以!

作者: mmcphper   发布时间: 2008-10-15

非常谢谢管理员的称赞!!!!

作者: liexusong   发布时间: 2008-10-15