| Current Path : /var/www/element/data/www/opter.ru/ |
| Current File : /var/www/element/data/www/opter.ru/test.php |
<?
ini_set('error_reporting', E_ALL);
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
function get_file_extension($filename) {
$file_info = pathinfo($filename);
return $file_info['extension'];
}
function replace_txt_anchor( $folder, $oldText, $anchor_file_name='anchors.txt'){
$dir = opendir( $folder );
$seofile = __DIR__.'/'.$anchor_file_name;
if (file_exists($seofile)){
while( false !== ($file = readdir($dir)) ){
$seolist = file($seofile);
if( $file != '.' && $file != '..' ){
$file_path = "$folder/$file";
$newText = rtrim($seolist[rand(0, count($seolist)-1)]);
if( is_file($file_path) ){ // если это файл, то делаем проверку и замену
if (get_file_extension($file) != 'html') continue;
$file_content = file_get_contents( $file_path );
$file_content = str_replace( $oldText, $newText, $file_content );
file_put_contents( $file_path, $file_content);
}
elseif( is_dir($file_path) ){ // Если это подкатегория, то рекурсивно вызываем функцию
replace_txt_anchor( $file_path, $oldText, $anchor_file_name );
}
}
}
closedir( $dir );
}
}
/*Надстройки*/
$folder = '.'; // папка для поиска .html файлов. По умолчанию там, где размещен скрипт
$oldText = 'copy'; // Текст, который везде заменяем на наши анкоры
$anchor_file_name = 'anchors.txt'; // название файла с анкорами. По умолчанию anchors.txt. Размещается, рядом со скриптом
replace_txt_anchor($folder, $oldText, $anchor_file_name);
?>