<?php
/***************************************************************************
Batch-replace, v1.1
***************************************************************************
file:batch-replace_utf8.php
Functionality: This program can scan all files in the specified directory for content substitution. It can be used to delete the horse in bulk and to update some contents of the page in bulk.
This procedure is suitable for modifying UTF-8 pages.
/***************************************************************************
*
* This are free software; You can redistribute it and/or modify
* It under the terms of the GNU lesser General public License as published by
* the free Software Foundation; Either version 2 of the License, or
* (at your option) any later version.
*
***************************************************************************/
Set_time_limit (3600);
if ($_post[' Submit ']== ' start to perform operation ') {
$dir = $_post[' SearchPath '];
$shortname = $_post[' shortname '];
$isall = $_post[' Isall '];
$isreg = $_post[' Isreg '];
if (!GET_MAGIC_QUOTES_GPC ()) {
$sstr = $_post[' sstr '];
$rpstr = $_post[' rpstr '];
} else {
$sstr = stripslashes ($_post[' sstr '));
$rpstr = stripslashes ($_post[' rpstr '));
}
Analysis ShortName
$arrext = Explode ("|", $shortname);
if (!is_dir ($dir)) return;
if ($sstr = = ") return;
Take the end of the/remove
if (substr ($dir, -1) = = '/') $dir = substr ($dir, 0,strrpos ($dir, "/"));
List all Catalogs
if ($isall = = 1) {
Hx_dirtree ($dir);
}else{
Hx_dealdir ($dir);
}
Exit ();
}
function Hx_dirtree ($path = ".") {
Global $sstr, $rpstr, $isreg, $arrext;
$d = Dir ($path);
while (false!== ($v = $d->read ())) {
if ($v = = "." | | $v = = "Continue");
$file = $d->path. " /". $v;
if (Is_dir ($file)) {
echo "<p> $v </p>"; Hx_dirtree ($file);
}else{
$ext =substr (STRRCHR ($v, "."), 1);
if (In_array ($ext, $arrext)) {
echo "<li> $file";
$body = file_get_contents ($file);
if ($isreg = = 1) {
$body 2 = preg_replace ($sstr, $rpstr, $body);
}else{
$body 2 = Str_replace ($sstr, $rpstr, $body);
}
if ($body!= $body 2 && $body 2!= ') {
ToFile ($file, $body 2);
Echo ' OK ';
}else{
Echo ' NO ';
}
Echo ' </li> ';
}
}
}
$d->close ();
}
function Hx_dealdir ($dir) {
Global $sstr, $rpstr, $isreg, $arrext;
if ($dh = Opendir ($dir)) {
while (false!== ($file = Readdir ($DH))) {
if (filetype ($dir. '/'. $file) = = ' file ') {
$ext =substr (STRRCHR ($file, "."), 1);
if (In_array ($ext, $arrext)) {
echo "<li> $file";
$body = file_get_contents ($dir. '/'. $file);
if ($isreg = = 1) {
$body 2 = preg_replace ($sstr, $rpstr, $body);
}else{
$body 2 = Str_replace ($sstr, $rpstr, $body);
}
if ($body!= $body 2 && $body 2!= ') {
ToFile ($dir. '/'. $file, $body 2);
Echo ' OK ';
}else{
Echo ' NO ';
}
Echo ' </li> ';
}
}
}
Closedir ($DH);
}
}
Write out a function of the process of generating a file
function ToFile ($file _name, $file _content) {
if (Is_file ($file _name)) {
@unlink ($file _name);
}
$handle = fopen ($file _name, "w");
if (!is_writable ($file _name)) {
return false;
}
if (!fwrite ($handle, $file _content)) {
return false;
}
Fclose ($handle); Close pointer
return $file _name;
}
? ><! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html xmlns= "http://www.w3.org/1999/xhtml" >
<head>
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">
<title> Batch Replacement Program | Trojan Batch Delete _www.itlearner.com</title>
<style type= "Text/css" >
Body{background: #FFFFFF; color: #000; font-size:12px;}
#top {text-align:center;}
h1,p,form{margin:0;padding:0;}
h1{font-size;14px;}
</style>
</head>
<body>
<div id= "Top" >
<h1> Batch Replacement Program (UTF-8 edition) </h1>
<div> This program can scan all files in the specified directory for <strong> content replacement </strong>. It can be used to delete the horse in bulk and to update some contents of the page in bulk. <br/>
In the case of a very large number of files, this operation is a comparison of server resources, make sure that the script timeout limit time allows changes, or you may not be able to complete the operation. </div>
</div>
<form action= "<?=$_server[' Script_name ']?>" Name= "Form1" target= "Stafrm" method= "POST" >
<table width= "border=" 0 "align=" center "cellpadding=" 3 "cellspacing=" 1 "bgcolor=" #666666 ">
<tr>
<TD width= "10%" bgcolor= "#FFFFFF" ><strong> start root path:</strong></td>
<TD width= "90%" bgcolor= "><input name=" SearchPath "type=" text "id=" SearchPath "value="./test "Size=" "/>
The point represents the current directory, the end does not add/<input type= "checkbox" Name= "Isall" value= "1"/> contains all directories under this directory </td>
</tr>
<tr>
<TD bgcolor= "#FFFFFF" ><strong> file name extension:</strong></td>
<TD bgcolor= "#FFFFFF" ><input name= "ShortName" type= "text" id= "ShortName" "size=" value= "php|htm"/>
Please use | separate </td>
</tr>
<tr id= "rpct" >
<TD height= "colspan=" 2 "bgcolor=" #FFFFFF "><table width=" 100% "border=" 0 "cellspacing=" 1 "cellpadding=" 1 " >
<tr bgcolor= "#EDFCE2" >
<TD colspan= "4" ><strong> content replacement options:</strong> <input type= "checkbox" Name= "Isreg" value= "1"/> Using regular Expressions </td>
</tr>
<tr>
<TD colspan= "4" > Replace content Classes use string substitution by default, or you can use regular expressions (tick-check). "Replace with" if not filled out, means to delete "replacement content." </td>
</tr>
<tr>
<TD width= "10%" > Replace content:</td>
<TD width= "36%" ><textarea name= "Sstr" id= "Sstr" style= "width:90%;height:45px" ></textarea></td >
<TD width= "10%" > Replaced by:</td>
<td><textarea name= "Rpstr" id= "Rpstr" style= "width:90%;height:45px" ></textarea></td>
</tr>
</table></td>
</tr>
<tr>
<TD colspan= "2" height= "align=" center "bgcolor=" #E2F5BC "><input type=" Submit "name=" Submit "value=" Start the operation "class=" Inputbut "/></td>
</tr>
</table>
</form>
<table width= "border=" 0 "align=" center "cellpadding=" 3 "cellspacing=" 1 "bgcolor=" #666666 ">
<tr bgcolor= "#FFFFFF" >
<TD id= "MTD" >
<div id= ' MDV ' style= ' width:100%;height:100; >
<iframe name= "stafrm" frameborder= "0" id= "stafrm" width= "100%" height= "100%" ></iframe>
</div>
<script type= "Text/javascript" >
Document.all.mdv.style.pixelHeight = screen.height-450;
</script> </td>
</tr>
</table>
</body>