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_
相关文档:
php和java通用sql语句法
SELECT max(id) from table
该方法在多线程等情况下可能会造成不正确。
java三种方法
1、根据ps的getGeneratedKeys
PreparedStatement ps = conn.prepareStatement(sql,Statement.RETURN_GENERATED_KEYS); //红色是关键
ps.executeUpdate(); //执行后
ResultSet rs = ps.getGeneratedKeys ......
header()函数用来转向(redirect page)时,如果调用前有输出,比如echo或html标签,就会转向失败。
如果调用前有空行也会转向失败。
还有一个原因,就是注意你的php文件的字符编码。我遇到的情况是,当字符编码为UTF-8时,转向失败,改为ANSI时成功。具体原因不明,仅供参考。 ......
看到同学们有不少在用php开发项目的,或许下面的资料对大家有用吧,用来学习一下也好。
收集的资料相关地址:
cubi demo site:http://dev.openbiz.cn/cubi/user/login
openBiz app cubi:http://docs.google.com/View?id=df5ktjv9_64f9fd88gf
openbiz architecture overview:
http: ......
转自 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 ......