全部的答案!!
时间: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
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28