1-5题本人愚解
时间:2008-10-15
来源:互联网
[php]
// NO.1
/**
* 遍历一个文件夹下的文件及子文件夹中的文件
* array function crawl_dirs(string $dir)
* $dir:路径
* print_r(crawl_dirs(dirname(__FILE__))); // return array();
*
*/
function crawl_dirs($dir)
{
$array = array();
$d = @dir($dir);
if($d){
while (false !== ($entry = $d->read())){
if($entry!='.' && $entry!='..'){
$key = $entry;
$entry = $dir.'/'.$entry;
if(is_dir($entry)){
$subdirs = crawl_dirs($entry);
if ($subdirs)
$array[$key] = $subdirs;
else
$array[] = $entry;
}else{
$array = array_merge($array, (array)$key);
}
}
}
$d->close();
}
return $array;
}
// NO.2
/**
* 对日期进行加减操作
*
* string adddate ( int $sub [, string $date ][, int $type ] )
*
* $sub : +增加 -减少.(天数)
* $date : 日期字符串或UNIX时间戳(取决于$type)[默认为time()]
* $type : 1表示$date字符串日期 否则为时间戳[默认为字符串日期]
*
* adddate(5,'2008-09-10'); // return 2008-9-15;
* adddate(4); // return now+4;
*/
function adddate($sub,$date = false,$type = 1){
if(!$date)
$date = time();
else
$date = $type ? strtotime ($date) : $date;
$oneday = 60*60*24;
$date += $oneday * $sub;
return date("Y-m-d",$date);
}
// NO.3
/**
* check_mail('[email protected]'); // 5555555纯数字
* check_mail('[email protected]'); // 用户名纯数字
* check_mail('[email protected]'); // 不可为163邮箱
* check_mail('[email protected]'); // OK
* check_mail('[email protected]'); // OK
* check_mail('[email protected]'); // OK
*
*/
function check_mail($mail){
// 不允许使用的
$_host = "(?!sina\.com(?!\.cn)|263\.com(?!\.cn)|163\.com(?!\.cn)|126\.com(?!\.cn)|qq\.com(?!\.cn))";
// 后缀格式
$host = "([a-z0-9\_-]*)[\.][a-z0-9]{2,3}([\.][a-z]{2})?";
// 格式验证正则
$base = "/^([0-9a-z\_-]+)@(".$_host.$host.")$/i";
// 数字正则
$num = "/^[\d]*$/i";
$pt = -1;
if (preg_match($base,$mail,$tmp)) {
//print_r($tmp);
if( preg_match($num,$tmp[1]) || preg_match($num,$tmp[3])){
return $pt;
}else{
if(1){
// 数据库查找是否重名 function dbcheck()
$pt = 1;
}
}
}
return $pt;
}
// NO.4 SQL语句
$sql = "select topic.*
from user,topic,rank
where user.rankid = rank.id and user.id = topic.userid
and topic.belongid = 5";
// NO.5 MySQL数据库中如何避免SQL注入(使用PHP编程方式实现。)
function inputfilter($input){
$input = trim($input);
$input = (! get_magic_quotes_gpc ()) ? addslashes ($input) : $input;
return $input;
}
[/php]
// NO.1
/**
* 遍历一个文件夹下的文件及子文件夹中的文件
* array function crawl_dirs(string $dir)
* $dir:路径
* print_r(crawl_dirs(dirname(__FILE__))); // return array();
*
*/
function crawl_dirs($dir)
{
$array = array();
$d = @dir($dir);
if($d){
while (false !== ($entry = $d->read())){
if($entry!='.' && $entry!='..'){
$key = $entry;
$entry = $dir.'/'.$entry;
if(is_dir($entry)){
$subdirs = crawl_dirs($entry);
if ($subdirs)
$array[$key] = $subdirs;
else
$array[] = $entry;
}else{
$array = array_merge($array, (array)$key);
}
}
}
$d->close();
}
return $array;
}
// NO.2
/**
* 对日期进行加减操作
*
* string adddate ( int $sub [, string $date ][, int $type ] )
*
* $sub : +增加 -减少.(天数)
* $date : 日期字符串或UNIX时间戳(取决于$type)[默认为time()]
* $type : 1表示$date字符串日期 否则为时间戳[默认为字符串日期]
*
* adddate(5,'2008-09-10'); // return 2008-9-15;
* adddate(4); // return now+4;
*/
function adddate($sub,$date = false,$type = 1){
if(!$date)
$date = time();
else
$date = $type ? strtotime ($date) : $date;
$oneday = 60*60*24;
$date += $oneday * $sub;
return date("Y-m-d",$date);
}
// NO.3
/**
* check_mail('[email protected]'); // 5555555纯数字
* check_mail('[email protected]'); // 用户名纯数字
* check_mail('[email protected]'); // 不可为163邮箱
* check_mail('[email protected]'); // OK
* check_mail('[email protected]'); // OK
* check_mail('[email protected]'); // OK
*
*/
function check_mail($mail){
// 不允许使用的
$_host = "(?!sina\.com(?!\.cn)|263\.com(?!\.cn)|163\.com(?!\.cn)|126\.com(?!\.cn)|qq\.com(?!\.cn))";
// 后缀格式
$host = "([a-z0-9\_-]*)[\.][a-z0-9]{2,3}([\.][a-z]{2})?";
// 格式验证正则
$base = "/^([0-9a-z\_-]+)@(".$_host.$host.")$/i";
// 数字正则
$num = "/^[\d]*$/i";
$pt = -1;
if (preg_match($base,$mail,$tmp)) {
//print_r($tmp);
if( preg_match($num,$tmp[1]) || preg_match($num,$tmp[3])){
return $pt;
}else{
if(1){
// 数据库查找是否重名 function dbcheck()
$pt = 1;
}
}
}
return $pt;
}
// NO.4 SQL语句
$sql = "select topic.*
from user,topic,rank
where user.rankid = rank.id and user.id = topic.userid
and topic.belongid = 5";
// NO.5 MySQL数据库中如何避免SQL注入(使用PHP编程方式实现。)
function inputfilter($input){
$input = trim($input);
$input = (! get_magic_quotes_gpc ()) ? addslashes ($input) : $input;
return $input;
}
[/php]
作者: 125231896 发布时间: 2008-10-15
都回答了呀
作者: dohelp 发布时间: 2008-11-17
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28