This article describes the PHP implementation of bulk Delete horse files and bulk replacement page content method. Share to everyone for your reference, specific as follows:
<?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 applicable to the UTF-8 of the page to modify. Set_time_limit (3600);
Script run time?> <?php if ($_post[' Submit ']== ' start executing 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;
The end/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 the process of generating the 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);
Turn off the pointer return $file _name; }?> <! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">