Php full-text search and replacement

Source: Internet
Author: User
: This article describes how to search and replace php in full text. For more information about PHP tutorials, see. Php full-text search and replacement

Exec ("/bin/grep-R' $ oldword' $ rootpath", $ results, $ errorCode );
If ($ errorCode ){
If ($ errorCode = 1 ){
Echo "Possibly no files were found with $ oldword in them
\ N ";
}
Echo "OS Error: $ errorCode
\ N ";
Echo "Check 'Man errno' and count down
\ N ";
Echo "Usually paths/permissions
\ N ";
}
While (list (, $ path) = each ($ results )){
$ Parts = explode (':', $ path );
$ Path = $ parts [0];
$ Fp = fopen ($ path, 'r') or PRint ("Cannot read $ path
\ N ");
If ($ fp ){
$ Data = fread ($ fp, filesize ($ path ));
Fclose ($ fp );
$ Newdata = str_replace ($ oldword, $ newword, $ data );
$ Fp = fopen ($ path, 'w') or print ("Cannot write $ path
\ N ");
If ($ fp ){
Fwrite ($ fp, $ newdata );
Fclose ($ fp );
Echo $ path ,"
\ N ";
}
}
}
?>
Example
Http://yourserver.com/globalreplace.php? Oldword = test & newword = text & rootpath =/path/to/dir

The above describes how to perform full-text search and replacement in php, including the full-text search and replacement content, and hopes to help those who are interested in PHP tutorials.

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.