- <?php
- //随机字幕数字组合
- function getRandomString($len, $chars=null){
- if (is_null($chars)){
- $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";}
- mt_srand(10000000*(double)microtime());
- for ($i = 0, $str = ”, $lc = strlen($chars)-1; $i < $len; $i++){
- $str .= $chars[mt_rand(0, $lc)];}
- return $str;
- }
- //搜索字符串位置
- function getCharpos2($str, $char){
- $j = 0;
- $arr = array();
- $count = substr_count($str, $char);
- for($i = 0; $i < $count; $i++){
- $j = strpos($str, $char, $j);
- $arr[] = $j;
- $j = $j+1;
- }
- return $arr;
- }
-
- $allpos=getCharpos2($s,’class="’);
- $poscount=count($allpos);
- $allcount=0;
- for($j=0 ; $j<$poscount; $j++){
- if($j==0){
- $s=substr_replace($s,getRandomString(7).’ ‘,$allpos[$j]+7,0);
- }else{
- $allcount=$allcount+8;
- $s=substr_replace($s,getRandomString(7).’ ‘,($allpos[$j]+$allcount)+7,0);
- }}
- ?>
复制代码
这个目前只能在class后插入,我想在class和id后插入或者更多标签后面插入,咋修改? |