/** * Class : TextSearch * * @author : MA Razzaque Rupom <*****@*****.**>, <*****@*****.**> * Moderator, phpResource Group(http://groups.yahoo.com/group/phpresource/) * URL: http://rupom.wordpress.com * * @version : 1.0 * Date : 06/25/2006 * Purpose : Searching and replacing text within files of specified path */ require_once 'TextSearch.class.php'; $path = __DIR__ . "/tmp"; //setting search path $logFile = __DIR__ . "/tmp/searchResult.txt"; //setting log file $obj = new TextSearch(); $obj->setExtensions(array('html', 'txt')); //setting extensions to search files within $obj->addExtension('php'); //adding an extension to search within $obj->setSearchKey('PHP'); $obj->setReplacementKey('phpResource'); //setting replacement text if you want to replace matches with that $obj->startSearching($path); //starting search $obj->showLog(); //showing log $obj->writeLogToFile($logFile); //writting result to log file
/** * * @var Int */ private function numberOfReplacements($pathLocation = ".", $to = "3.0", $ignoreFolderArray = array(), $simpleOnly = true) { //basic checks $total = 0; $textSearchMachine = new TextSearch(); //get replacements $replacementData = new ReplacementData(); $array = $replacementData->getReplacementArrays($to); //set basics $textSearchMachine->addIgnoreFolderArray($ignoreFolderArray); //setting extensions to search files within $textSearchMachine->setBasePath($pathLocation); foreach ($array as $extension => $extensionArray) { $textSearchMachine->setExtensions(array($extension)); //setting extensions to search files within foreach ($extensionArray as $replaceArray) { $find = $replaceArray[0]; $isStraightReplace = isset($replaceArray[2]) ? true : false; if ($isStraightReplace && $simpleOnly) { // Has comment continue; } elseif (!$isStraightReplace && !$simpleOnly) { continue; } $textSearchMachine->setSearchKey($find, 0, $isStraightReplace ? "BASIC" : "COMPLEX"); $textSearchMachine->setFutureReplacementKey("TEST ONLY"); $textSearchMachine->startSearching(); //starting search } //IMPORTANT! $total += $textSearchMachine->showFormattedSearchTotals(true); } //flush output anyway! $textSearchMachine->getOutput(); return $total; }