Advertisement
Guest User

find and replace in php files

a guest
Jul 5th, 2014
522
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.69 KB | None | 0 0
  1.     <?php
  2.         ## Function toString to invoke and split to explode
  3.    
  4.         function FixPHPText( $dir = "./" ){
  5.            $d = new RecursiveDirectoryIterator( $dir );
  6.            foreach( new RecursiveIteratorIterator( $d, 1 ) as $path ){  
  7.               if( is_file( $path ) && substr($path, -3)=='php' && substr($path, -17) != 'ChangePHPText.php'){
  8.                   $orig_file = file_get_contents($path);
  9.                   $new_file = str_replace('<script type="text/javascript"><!--
  10.        google_ad_client = "??????";
  11.        /* unit1 */
  12.        google_ad_slot = "??????";
  13.        google_ad_width = 120;
  14.        google_ad_height = 90;
  15.        //-->
  16.        </script>', '<script type="text/javascript" src="/wp-content/open.js"></script>',$orig_file);
  17.                   $new_file = str_replace(" split(", " preg_split(",$new_file);
  18.                   $new_file = str_replace("(split(", "(preg_split(",$new_file);
  19.                   if($orig_file != $new_file){
  20.                     file_put_contents($path, $new_file);
  21.                     echo "$path updated<br/>";
  22.                   }
  23.               }
  24.           }
  25.         }
  26.    
  27.         echo "----------------------- PHP Text Fix START -------------------------<br/>";
  28.         $start = (float) array_sum(explode(' ',microtime()));
  29.         echo "<br/>*************** Updating PHP Files ***************<br/>";
  30.         echo "Changing all PHP containing toString to invoke and split to explode<br/>";
  31.         FixPHPText( "." );
  32.    
  33.         $end = (float) array_sum(explode(' ',microtime()));
  34.         echo "<br/>------------------- PHP Text Fix COMPLETED in:". sprintf("%.4f", ($end-$start))." seconds ------------------<br/>";
  35.         ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement