Рекурсивный акроним словосочетания «PHP: Hypertext Preprocessor»
Добро пожаловать на форум PHP программистов!
За последние 24 часа нас посетили 17154 программиста и 1834 робота. Сейчас ищут 1654 программиста ...
Introduction
Вернуться к: File_SearchReplace
Introduction
Introduction – HowTo s'n'r in files
With SearchReplace, you can replace a text in as many as desired files by another.
Typical usage
<?php
include 'File/SearchReplace.php' ;
$files = array( "test1.txt",
"test2.txt",
"test3.txt" ) ;
$ignoreline = array( "#", ":") ;
$snr = new File_SearchReplace( "Yes", "No", $files, "/mail/", false,
$ignoreline) ;
$snr -> doSearch() ;
?>
The example replaces all occurences of "Yes" with "No" in the given $files and in all files in the directory "/mail/". If a line in a file starts with one of the chars in $ignoreline, possible matches will be ignored.
You can do a new search without creating a new instance of the class.
Do a new search
<?php
...
// string to search
$snr -> setFind( "Er") ;
// string to find
$snr -> setReplace( "Sie") ;
// look in this files
$snr -> setFiles( $files) ;
// look in this directories
$snr -> setDirectories( array( "/neue_briefe/")) ;
// look in the subdirectories too
$snr -> setIncludeSubdir( true) ;
// ignore lines in the files starting with this chars
$snr -> setIgnoreLines( array( "::", "#")) ;
// restart search'n'replace
$snr -> doSearch() ;
?>
Types of search functions
File_SearchReplace supports different kinds of search functions. The type directly influence the format of the required $find-parameter
- normal - default, the only type supporting the $IgnoreLines-parameter
- quick - use str_replace()
- preg - use preg_replace()
- ereg - use ereg_replace()
Вернуться к: File_SearchReplace