PHP implementation of bulk Delete horse files and bulk replacement page content Complete Example _php tips

Source: Internet
Author: User
Tags php programming php regular expression

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 "> 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.