• 心情随笔

二宝博客

好记性不如赖笔头
二宝博客
  • android中CleartextHTTP错误解决方案
  • 示例页面
  • 首页
  • php
    • Thinkphp
  • JS相关
  • 服务器
    • Linux
    • Windows
    • xenserv
  • DIVCSS
  • MAC
  • 软件分享
  • 关键字 替换类 替换(随机位置) 且指定数量的关键词

    关键字 替换类  替换(随机位置) 且指定数量的关键词

    array(“Key”=>”this”,”Href”=>”this“,”ReplaceNumber”=>1),     1=>array(“Key”=>”test”,”Href”=>”test“,”ReplaceNumber”=>1) ); $str = “this is test content!”; $a = new Seokey($KeyArray,$str); $a->KeyOrderBy(); $a->Replaces(); echo $a->HtmlString; */ class Seokey{     public $KeyArray;  //关键字     public $HtmlString; //文字内容     public $ArrayCount; //关键字的个数     public $Key;     public $Href;     /*         初始化:         $keyArray 关键字 数组         $String   检索字域,文字     */     function Seokey($KeyArray,$String,$Key='Key',$Href='Href'){        $this->KeyArray=$KeyArray;        $this->HtmlString=$String;        $this->ArrayCount=count($KeyArray);        $this->Key=$Key;        $this->Href=$Href;     }     /*         关键字 按长度排序     */     function KeyOrderBy(){         usort($this->KeyArray,'sortcmp');     }     function Replaces(){                      for($i=0;$i<$this->ArrayCount;$i++){             if((integer)$this->KeyArray[$i]['ReplaceNumber'] != 0 ){                 str_replace($this->KeyArray[$i][$this->Key],”/*”.md5($this->KeyArray[$i][$this->Key]).”*/”,$this->HtmlString,$num);//$num查询到的数量                 if((integer)$this->KeyArray[$i]['ReplaceNumber']>$num) {//当关键词 需要替换的数量 大于 包含的数量时,替换全部                     $this->KeyArray[$i]['ReplaceNumber']=$num;                     $this->HtmlString=str_replace($this->KeyArray[$i][$this->Key],”/*”.md5($this->KeyArray[$i][$this->Key]).”*/”,$this->HtmlString);                     continue;                 }                 //当关键词 需要替换的数量 不大于 包含的数量时,使用 KeyStrpos($i);方法替换                 $ListNumber=array();                 $ListNumber=$this->KeyStrpos($i);//$i: 表示第$i个关键词($i从0开始)                 $RegArray=array();                 if(count($ListNumber)<1) continue;//不存在 关键词                 $n=0;                 while($n<(integer)$this->KeyArray[$i][“ReplaceNumber”]){                     $g=0;                     $x=rand(0,count($ListNumber)-1);//随机数                     for($xcn=0;$xcn<=$n;$xcn++){                         if($RegArray[$xcn]==$ListNumber[$x]){                             $g=1;                         }                     }                     if($g==0){                         $RegArray[$n]=$ListNumber[$x];                         $n++;                     }                 }                 for($c=0;$c$RegArray[$jx]){                             $TempArray=$RegArray[$c];                             $RegArray[$c]=$RegArray[$jx];                             $RegArray[$jx]=$TempArray;                         }                     }                 }                 for($c=0;$cStrposKey($this->KeyArray[$i][$this->Key],$RegArray[$c],$c);// 逐位(索引位) 替换截取到的关键字                 }                $this->HtmlString=str_replace(“/&”.md5($this->KeyArray[$i][$this->Key]).”&/”,$this->KeyArray[$i][$this->Key],$this->HtmlString);             }else{                $this->HtmlString=str_replace($this->KeyArray[$i][$this->Key],”/*”.md5($this->KeyArray[$i][$this->Key]).”*/”,$this->HtmlString);             }        }        for($i=0;$i<$this->ArrayCount;$i++){            $this->HtmlString=str_replace(“/*”.md5($this->KeyArray[$i][$this->Key]).”*/”,$this->KeyArray[$i][$this->Href],$this->HtmlString);        }     }     function StrposKey($Key,$StrNumber,$n){//在字符串里 截取关键字 并替换,从$StrNumber这个位置开始(包含$StrNumber这个位置)替换到$n(包含$n这个位置)这个位置        $this->HtmlString=substr_replace($this->HtmlString, “/*”.md5($Key).”*/”, $StrNumber, 36);     }     /* 递归 查找 关键词 所在的位置 存于数组中 */     function KeyStrpos($KeyId){         $StrListArray=array();         $StrNumberss=strpos($this->HtmlString, $this->KeyArray[$KeyId][$this->Key]);         $xf=0;         while(!($StrNumberss===false)){             $StrListArray[$xf]=$StrNumberss;             $this->HtmlString=substr_replace($this->HtmlString,”/&”.md5($this->KeyArray[$KeyId][$this->Key]).”&/”,$StrNumberss, strlen($this->KeyArray[$KeyId][$this->Key]));             $StrNumberss=strpos($this->HtmlString, $this->KeyArray[$KeyId][$this->Key]);             $xf++;         }         return $StrListArray;     }     } ?>

    ]]>

    键盘游走者 发布于 2017-01-04 22:41php抢沙发
    查看
  • 新年新气象!让2016把带走一切的不愉快,2017努力吧!

    新年新气象!让2016把带走一切的不愉快,2017努力吧!

    RT

    ]]>

    键盘游走者 发布于 2017-01-04 22:40心情随笔抢沙发
    查看
  • 列目录程序Directory Lister H5ai

    列目录程序Directory Lister H5ai

    https://larsjung.de/h5ai/

    http://www.directorylister.com/

    ]]>

    键盘游走者 发布于 2016-12-13 19:20php抢沙发
    查看
  • Cron定时任务应用到Thinkphp

    Cron定时任务应用到Thinkphp

              安装crontab:           yum install crontabs                 关于cron的一些命令:           /sbin/service crond start //启动服务              /sbin/service crond stop //关闭服务              /sbin/service crond restart //重启服务              /sbin/service crond reload //重新载入配置   ...

    键盘游走者 发布于 2016-11-25 00:45Thinkphp抢沙发
    查看
  • webuploader上传多实例,一个页面多个上传按钮

    webuploader上传多实例,一个页面多个上传按钮

    一个项目中用到了 webuploader ,页面中需要一个页面多个实例,经过查看多种方法得出以下结论 在页面按钮处添加一个公用的类 filePicker,然后 onclick 写一个方法, class="filePicker" onclick="addWebuploadCurrent('banners')" 当触发时给input一个类     function addWebu ...

    键盘游走者 发布于 2016-11-14 20:22php抢沙发
    查看
  • Thinkphp中eq,neq,gt,lt等表达式缩写

    Thinkphp中eq,neq,gt,lt等表达式缩写

    eq 等于
    neq 不等于
    gt 大于
    egt 大于等于
    lt 小于
    elt 小于等于
    like LIKE
    between BETWEEN
    notnull IS NUT NULL
    null IS NULL

    ]]>

    键盘游走者 发布于 2016-11-09 20:49Thinkphp抢沙发
    查看
  • 汉字转换为拼音的JavaScript库

    汉字转换为拼音的JavaScript库

    摘要: 转自:http://my.oschina.net/ihotte/blog/66153 的好工具。汉字转换为拼音的JavaScript库 将JSPinyin剥离mootools这个JavaScript库,可以独立使用。 1)一个是将汉字翻译为拼音,其中每一个字的首字母大写;   pinyin.getFullChars(this.value); 2)一个是可以将每一个字的拼音的首字母提取出来 ...

    键盘游走者 发布于 2016-11-07 22:11JS相关抢沙发
    查看
  • 向一个字符串随机位置插入一个字符串

    向一个字符串随机位置插入一个字符串

    /** * 向一个字符串随机插入一个字符串 * @param unknown_type $oldstr    老字符串 * @param unknown_type $instr    插入的字符串 * @param unknown_type $encoding    字符串编码 */ function rand_in_str($oldstr,$instr,$encoding){ $len = mb_strlen($oldstr,$encoding); $insert_point = mt_rand(1,$len-1); $pr ...

    键盘游走者 发布于 2016-10-31 19:26php抢沙发
    查看
  • egister_shutdown_function 函数详解

    egister_shutdown_function 函数详解

    php开发测试及线上的时候可以根据不同情况设定错误和异常处理需要用到有 设定错误和异常处理三函数 register_shutdown_function(array(‘Debug’,'fatalError’)); //定义PHP程序执行完成后执行的函数set_error_handler(array(‘Debug’,'appError’)); // 设置一个用户定义的错误处理函数set_exception_handle ...

    键盘游走者 发布于 2016-10-21 17:51php抢沙发
    查看
  • Tinyurl API方法

    Tinyurl API方法

    ]]>

    键盘游走者 发布于 2016-10-20 00:13php抢沙发
    查看
« 上一页 1 … 16 17 18 19 20 … 41 下一页 »
2026 年 8 月
一 二 三 四 五 六 日
 12
3456789
10111213141516
17181920212223
24252627282930
31  
« 6 月    

归档

  • 最新日志
  • 热评日志
  • 随机日志
  • 宝塔面板安装Perl,支持cgi pl 程序运行
  • 局域网打印机修复工具,能解决90%局域网共享问题
  • 海康威视IVMS-4200 2.0.0.18 For MacOS
  • MobaXterm 26.4 中文汉化版
  • MySQL部署工具 v8.4.9
  • 飞牛部署JumpServer Mysql报错解决办法FNNAS
  • DHCP 服务器查找器
  • 增强版tracert
  • 开心电视助手V8.2,支持安卓4.4-14 
  • 如何在Windows 7电脑上删除系统服务
  • 开心电视助手V8.2,支持安卓4.4-14 
  • 增强版tracert
  • DHCP 服务器查找器
  • 飞牛部署JumpServer Mysql报错解决办法FNNAS
  • MySQL部署工具 v8.4.9
  • MobaXterm 26.4 中文汉化版
  • 海康威视IVMS-4200 2.0.0.18 For MacOS
  • 局域网打印机修复工具,能解决90%局域网共享问题
  • 宝塔面板安装Perl,支持cgi pl 程序运行
  • 史上最全华为路由器交换机配置命令大合集
  • 留言给我
  • 摆脱流氓 Adobe Flash Player 32.0.0.303 绿色特别版
  • 向一个字符串随机位置插入一个字符串
  • 无需插件实现拦截无中文或有日文垃圾评论
  • 自建JetBrains激活服务器[ZT]
  • 恭祝大家新年快乐!
  • VMWARE6.0+Centos5.3+Squid2.6构建反向代理环境
  • PHP获取服务器详细信息
  • ie11卸载报错?ie11卸载不了怎么办?升级了IE后悔了怎么办?
  • 给博客添加运行时间

最活跃的读者

最新评论

友情链接

  • 大宝博客
  • 白俊遥

Copyright © 2008 二宝博客. Powered by WordPress. Theme by Weisay. 豫ICP备2023032064号-1.