php 随机class和 僵尸元素的实现
1.参考自己的文章
php中preg_replace_callback函数同一个正则,替换成不同内容
https://www.cnblogs.com/cn-oldboy/p/17149911.html
2.僵尸元素的实现。
暂无思路
3.代码案例
<?php
$html=file_get_contents('http://xxxxxx.com');
// class10位随机字符  substr(md5(uniqid(mt_rand(), true)), 0, 8)
$replace='/class="/i';
 $html=preg_replace_callback(
  $replace,
  function(){
//   static $i;
//   $i=$i+1;
   return 'class="'.substr(md5(uniqid(mt_rand(), true)), 0, 10).' '.substr(md5(uniqid(mt_rand(), true)), 0, 10).' ';
  },
  $html
 );
 
 
//  div追加僵尸元素
$replace='/<\/div>/i';
 $html=preg_replace_callback(
  $replace,
  function(){
//   static $i;
//   $i=$i+1;
   return '<address style="display:none" ></address>'.'</div>';
  },
  $html
 );
 
 
//  去掉注释
// $replace='/\/\/\s*.*\n$/i';
//   $html=preg_replace_callback(
//   $replace,
//   function(){
// //   static $i;
// //   $i=$i+1;
//   return '';
//   },
//   $html
//  );
 
//  去掉空行
// $replace='/[\n]/i';
//   $html=preg_replace_callback(
//   $replace,
//   function(){
// //   static $i;
// //   $i=$i+1;
//   return '';
//   },
//   $html
//  );
echo $html;
 
                    
                
 
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号