21个实用便利的PHP代码
1. PHP可阅读随机字符串
此代码
将创建一个可阅读的字符串,使其更接近词典中的单
词,实用且具有密码验证功能。
/**************
[email=*@length]*@length[/email] - length of random string (must be a
multiple of 2)
**************/
function readable_random_string($length = 6){
$conso=array("b","c","d","f","g","h","j","k","l",
"m","n","p","r","s","t","v","w","x","y","z");
$vocal=array("a","e","i","o","u");
$password="";
srand ((double)microtime()*1000000);
$max = $length/2;
for($i=1; $i<=$max; $i++)
{
$password.=$conso[rand(0,19)];
$password.=$vocal[rand(0,4)];
}
return $password;
}
2. PHP生成一个随机字符串
如果不需要可阅读的字符串,使用此函数替代,即可创建一个随机字符串,作为用户的随机密码等。
/*************
[email=*@l]*@l[/email] - length of random string
*/
function generate_rand($l){
$c= "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
srand((double)microtime()*1000000);
for($i=0; $i<$l; $i++) {
$rand.= $c[rand()%strlen($c)];
}
return $rand;
}
3. PHP编码电子邮件地址
使用此代码,可以将任何电子邮件地址编码为 html 字符实体,以防止被垃圾邮件程序收集。
function encode_email([email=$email=]$email='info@domain.com'[/email],
$linkText='Contact Us', $attrs ='class="emailencoder"' )
{
// remplazar aroba y puntos
$email = str_replace([email=]'@'[/email], '@', $email);
$email = str_replace('.', '.', $email);
$email = str_
相关文档:
通讯录已经大致完成了,但如果记录数多时,查找起来很不方便,如果加一个搜索功能就好了。今天我们就来制作一个搜索功能
在Index.php合适的地方加入搜索框
<!---搜索框--->
<!--这里的所有值前面加前缀“S_”以区分-->
<form id="form1" name="form1" method="post" action="Search.php ......
<?php
$p=new ReflectionClass(类对象);
$constants=$p->getConstants();//const 定义常量
$properties=$p->getProperties();//所有变量属性
$methods=$p->getMethods();//所有方法
//全部以数组形势返回
?> ......
转自 http://wiki.kuaizhanbao.com/2009/1210/245.html
basename — 返回路径中的文件名部分
chgrp — 改变文件所属的组
chmod — 改变文件模式
chown — 改变文件的所有者
clearstatcache — 清除文件状态缓存
copy — 拷贝文件
delete — 参见 unlink() 或 unset()
di ......
GyPSii利用XML-RPC,PHP里XML-RPC的相关应用示例很多,查查手册、GOOGLE一下就可以找到很多。GyPSii API里提供了一个操作类用来请求服务,并提供了一个请求函数,只要将此函数放进操作类里,就可以方便的使用了,函数如下:
function GyPSiiXMLRPC( $uri, $host, $pid, $body="" ) {
$this->addHeader( 'Content-T ......
PHP在运行的时候,直接kill掉,有肯能造成数据的丢失。幸好php模块,有针对signal的处理。
处理方式,首先检查有没有安装 PCNTL 模块
然后可以在一个包含文件中,添加以下代码
global $exitFlag;
$exitFlag = false;
// 增加linux信号量处理
if (DIRECTORY_SEPARATOR != '\\') {
pcntl_signal(SI ......