virt2/import/php/crophtml.php

80 lines
2.0 KiB
PHP
Executable File

<?php
function replacer_param ($text) { // ФУНКЦИЯ очистки кода
$old1 = array('<table id="PriceTable" border=0 cellpadding=0 cellspacing=3>');#Ищем вредное ">",, "<"
$new1 = array('<table class=table>');#Меняем на полезное"&gt;", , "&lt;"
$text = str_replace($old1, $new1, $text);#Собсно сама замена =)
return $text; }
$src='/media/backup/goodhtml';
function list_file ( $dir ) {
if ( $dir [ strlen( $dir ) - 1 ] != '/' )$dir .= '/';
$nDir = opendir( $dir );
while ( false !== ( $file = readdir( $nDir ) ) )
{if ( $file != "." AND $file != ".." ){
if ( !is_dir( $dir . $file ) )$files [] = $file;}
}closedir( $nDir );
return $files;}
//Получаем список файлов
$all_files=list_file($src);
//Ищем нужный файл
$count = count($all_files);
for($x=0; $x<$count; $x++){
$txt = "";
$fd = fopen( $src . '/' . $all_files[$x], "r");
while (!feof($fd)) {
$txt .= fgets($fd, 5000);
}
fclose ($fd);
$begin1=strpos($txt, '<table id="PriceTable" border=0 cellpadding=0 cellspacing=3>', 0);
//echo $begin . "\n";
$rest = substr($txt, $begin1, strlen($txt));
//$begin=strpos($txt, '</table>');
//$rest = substr($txt, $begin1, $begin-1);
//echo $rest;
$f = fopen($src . '/' . $all_files[$x], 'w');
fputs($f,replacer_param( $rest ) );
fclose($f);
}
//очищаем конец
for($x=0; $x<$count; $x++){
$txt = "";
$fd = fopen( $src . '/' . $all_files[$x], "r");
while (!feof($fd)) {
$txt .= fgets($fd, 5000);
}
fclose ($fd);
$begin1=strpos($txt, '</table>', 0);
//echo $begin . "\n";
$rest = substr($txt, 0, $begin1) . '</table>';
//$begin=strpos($txt, '</table>');
//$rest = substr($txt, $begin1, $begin-1);
//echo $rest;
$f = fopen($src . '/' . $all_files[$x], 'w');
fputs($f,replacer_param( $rest ) );
fclose($f);
}
?>