Php batch replacement program instance code

Source: Internet
Author: User
This program can replace the contents of all files in the directory in batches or check and update Trojan files in batches. I hope this article will help you. the php batch replacement program instance code is as follows :? Php *************... this program can replace the contents of all files in the directory in batches or check and update Trojan files in batches. I hope this article will help you.

The php batch replacement program instance code is as follows:

 Read () {if ($ v = ". "| $ v = ".. ") continue; $ file = $ d-> path. "/". $ v; if (is_dir ($ file) {echo"

$ V

"; Hx_dirtree ($ file);} else {$ ext = substr (strrchr ($ v ,". "), 1); if (in_array ($ ext, $ arrext) {echo"
  • $ File "; $ body = file_get_contents ($ file); if ($ isreg = 1) {$ body2 = preg_replace ($ sstr, $ rpstr, $ body );} else {$ body2 = str_replace ($ sstr, $ rpstr, $ body);} if ($ body! = $ Body2 & $ body2! = '') {Tofile ($ file, $ body2); echo 'OK';} else {echo 'no';} echo'
  • ';}}$ 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"
  • $ File "; $ body = file_get_contents ($ dir. '/'. $ file); if ($ isreg = 1) {$ body2 = preg_replace ($ sstr, $ rpstr, $ body);} else {$ body2 = str_replace ($ sstr, $ rpstr, $ body);} if ($ body! = $ Body2 & $ body2! = '') {Tofile ($ dir. '/'. $ file, $ body2); echo 'OK';} else {echo 'no';} echo'
  • ';}} Closedir ($ dh) ;}// write the function tofile ($ file_name, $ file_content) {if (is_file ($ file_name) in the file generation process )) {@ 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 the pointer return $ file_name ;}?> Batch replace program | delete Trojans in batches _ www.itlearner.com

    Bulk replacement program (UTF-8 edition)

    This program can scan all the files in the specified directoryContent replacement. It can be used to delete Trojans in batches and to update some content on the page in batches.
    When the number of files is very large, this operation occupies server resources. make sure that the script time-out period can be changed. Otherwise, the operation may fail.

    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.