PHP向一个字符串随机添加文字
很久前在baidu回答问题时写的“向一个字符串随机添加文字”的解决方案,可以支持中英文
<?php
/*********************************************************
describe:字符串处理,可以处理中英文
function:向一个字符串随机添加文字
author: etongchina
email2me: etongchina@gmail.com
time: 2008-06-24
blog: http://etongchina.blogcn.com
*********************************************************/
function getStrlen($str){
$_count = array();
$count = 0;
for($count;$count<strlen($str);){
ord($str{$i})>127?$count+=2:$count++;
$_count[] = $count; //用数组存储可能插入的位置
}
$_key = array_rand($_count); //从数组中获取随机键
return $_count[$_key];
}
$str = "伟大祖国繁荣富强"; //源字符串
$insert_str = "-"; //待添加的文字
$_rand = getStrlen($str); //主函数
$_exp = "/^(.{".$_rand."})(.*)$/i"; //正则表达式
$t = preg_replace($_exp,"$1{$insert_str}$2",$str);
print $t;
?>
相关文档:
get_class_methods() // 所有方法
get_included_files()//返回当前页所有加载的文件
get_declared_classes()// 返回当前页所有class
get_declared_interfaces()// 返回所有的接口
get_defined_functions()// 返回所有的function &nb ......
中国第一档绿色PHP资源分享门户,专注于创新和原创类源码php资源,原创视频php资源,原创典型模块php资源,原创php开源资源,原创php教程资源,原创网站模板资源 。网站地址 http://www.phpzy.com/
绿色php资源 ......
计划任务(Schedule Task)是windows平台上和cron类似的一个程序,当然功能上差了很多了。
因为需要每个小时运行一个PHP程序,手动操作不现实了。
首先在cmd下测试,例如: c:\appserv\php5\php.exe "C:\AppServ\www\temp2.php"
有一点要注意就是如果那个PHP引用了其他页面,需要提供绝对路径了,至少我的测试 ......
其实这篇文章也不能算作是原创,只是在原作者的基础上修改的比较多,几乎重写了一遍。
<?php
/**
*在原作者的基础上修改的,呵呵,不过忘记了原作者是谁了,
*如果原作者看到的话,给我一个提示,o(∩_∩)o...
*我的blog:http://etongchina.blogcn.com
*我的邮箱:etongchina@gmail.com
**/
fu ......