全部博文(315)
分类:
2007-05-24 10:16:24
1、Benchmark组件 计算页面执行时间
include_once "Benchmark/Timer.php";
$timer=new Benchmark_Timer();
$timer->start();
echo "Hello World";
$timer->stop();
$totaltime=$timer->timeElapsed();
echo "
本页执行时间为" .$totaltime ."秒"
2、Date组件 Show日期Detail
require_once 'Date.php';
require_once 'Date/Span.php';
$date = new Date();
$tmp = new Date($date);
printf("当前时间: %s\n", $date->getDate(DATE_FORMAT_ISO));
print '
';
$tmp->copy($date);
$tmp->subtractSpan(new Date_Span('0:00:00:05'));
printf("之前 5 秒: %s\n", $tmp->getDate(DATE_FORMAT_ISO));
print '
';
$tmp->copy($date);
$tmp->subtractSpan(new Date_Span('0:00:20:00'));
printf("之前 20 分: %s\n", $tmp->getDate(DATE_FORMAT_ISO));
print '
';
$tmp->copy($date);
$tmp->subtractSpan(new Date_Span('0:10:00:00'));
printf("之前 10 时: %s\n", $tmp->getDate(DATE_FORMAT_ISO));
print '
';
$tmp->copy($date);
$tmp->subtractSpan(new Date_Span('03:00:00:00'));
printf("之前 3 天: %s\n", $tmp->getDate(DATE_FORMAT_ISO));
print '
';
$tmp->copy($date);
$tmp->subtractSpan(new Date_Span('3:10:20:05'));
printf("之前 3 天, 10 时, 20 分 和 5 秒: %s\n", $tmp->getDate(DATE_FORMAT_ISO));
print '
';
$tmp->copy($date);
$tmp->addSpan(new Date_Span('0:00:00:05'));
printf("之后 5 秒: %s\n", $tmp->getDate(DATE_FORMAT_ISO));
print '
';
$tmp->copy($date);
$tmp->addSpan(new Date_Span('0:00:20:00'));
printf("之后 20 分: %s\n", $tmp->getDate(DATE_FORMAT_ISO));
print '
';
$tmp->copy($date);
$tmp->addSpan(new Date_Span('0:10:00:00'));
printf("之后 10 时: %s\n", $tmp->getDate(DATE_FORMAT_ISO));
print '
';
$tmp->copy($date);
$tmp->addSpan(new Date_Span('3:00:00:00'));
printf("之后 3 天: %s\n", $tmp->getDate(DATE_FORMAT_ISO));
print '
';
$tmp->copy($date);
$tmp->addSpan(new Date_Span('3:10:20:05'));
printf("之后 3 天, 10 时, 20 分 和 5 秒: %s\n", $tmp->getDate(DATE_FORMAT_ISO));
print '
';
3、HTML_QuickForm组件 快速开发Form程序
require_once("HTML/QuickForm.php");
//建立一个表单对象
$form = new HTML_QuickForm('frmTest', 'post');
$form->addElement('header', 'header', '请登录');
$form->addElement('text', 'name', '用户名:');
$form->addElement('password', 'password', '密码:');
$form->addElement('text','email','邮箱地址:');
$form->addElement('file','input','输入文件');
$form->addElement('submit', 'submit', '提交');
// 输出到浏览器
$form->addRule('name','用户名不能为空!', 'required','','client');
$form->addRule('name','用?名必??3位以上字母或?字','minlength',3,'client');
$form->addRule('password','密?不能位空!','required','','client');
$form->addRule('password','密??度必?大于6','minlength',6,'client');
$form->addRule('email','邮箱不能为空','required','','client');
$form->addRule('email','请输入合法的邮箱','email','','client');
$form->addRule('input','请选择文件','required','','client');
$form->addRule('input','请选择文件','uploadedfile','','client');
if($form->validate()){
$form->process('say_hello');
}else {
$form->display();
}
function say_hello($data){
print 'Hello,' .$data['name'];
print '
';
print 'Your password is ' .$data['password'];
print '
';
print 'Your ?箱 is ' .$data['email'];
}
4、Text_Password组件 快速加密指定字符串和随机
require_once "Text/Password.php";
echo "\n密码原文为: 'haohappy', 加密方法为: 'reverse',
加密结果为:";
echo Text_Password::createFromLogin('haohappy', 'reverse') . "
";
echo "\n密码原文为 'haohappy', 加密方法为: 'rot13',
加密结果为:";
echo Text_Password::createFromLogin('haohappy', 'rot13') . "
";
echo "\n密码原文为 'haohappy', 加密方法为: 'rotx',
加密结果为:";
echo Text_Password::createFromLogin('haohappy', 'rotx', 13) . "
";
echo "\n密码原文为 'haohappy', 加密方法为: 'rotx++',
加密结果为:";
echo Text_Password::createFromLogin('haohappy', 'rotx++', 13) . "
";
echo "\n密码原文为 'haohappy', 加密方法为: 'rotx--',
加密结果为:";
echo Text_Password::createFromLogin('haohappy', 'rotx--', 13) . "
";
echo "\n密码原文为 'haohappy', 加密方法为: 'xor',
加密结果为:";
echo Text_Password::createFromLogin('haohappy', 'xor', 5) . "
";
echo "\n密码原文为 'haohappy', 加密方法为: 'ascii_rotx',
加密结果为:";
echo Text_Password::createFromLogin('haohappy', 'ascii_rotx', 5) . "
";
echo "\n密码原文为 'haohappy', 加密方法为: 'ascii_rotx++',
加密结果为:";
echo Text_Password::createFromLogin('haohappy', 'ascii_rotx++', 5) . "
";
echo "\n密码原文为 'haohappy', 加密方法为: 'ascii_rotx--',
加密结果为:";
echo Text_Password::createFromLogin('haohappy', 'ascii_rotx--', 5) . "
";
echo "\n密码原文为 'haohappy', 加密方法为: 'shuffle',
加密结果为:";
echo Text_Password::createFromLogin('haohappy', 'shuffle', 1) . "
";
echo "\n密码组原文为: 'haohappy', 'martin', 'vanhoucke', 'jansen', 加密方法为: 'reverse':\n";
$logins = array('haohappy', 'martin', 'vanhoucke', 'jansen');
echo "结果如下:
";";
print_r(Text_Password::createMultipleFromLogin($logins, 'reverse'));
echo "
echo "创建一个10字符的不可发音密码....:
";
echo Text_Password::create(10, 'unpronounceable') . "
";
echo "创建一个8字符且只包含有a,b,c的不可发音密码....:
";
echo Text_Password::create(8, 'unpronounceable', 'a,b,c') . "
";
echo "
同时创建4个不可发音密码...:\n
";
print_r(Text_Password::createMultiple(4, 10, 'unpronounceable'));
echo "
";
echo "创建一个长度为8的只含有数字的不可发音密码:
";
echo Text_Password::create(8, 'unpronounceable', 'numeric') . "
";
echo "创建一个长度为8的只包含数字或字母的不可发音密码::
";
echo Text_Password::create(8, 'unpronounceable', 'alphanumeric') . "
";