Показать сообщение отдельно
Старый 07.06.2006, 17:15     # 4
smap
Junior Member
 
Аватар для smap
 
Регистрация: 14.10.2002
Адрес: Samara
Сообщения: 84

smap Путь к славе только начался
Wink

Пора уже на php5 переходить

Вообщем мини класс накатал, в друг кому пригодиться
Код:
<?php

class replaceFiles {

    private $array_file;
    private $ereg = "/.+/";

    function __construct( $path ) {
        $this->path = $path;
    }

    public function ereg( $ereg ) {
        $this->ereg = $ereg;
    }

    public function replace( $search, $replace ) {
        $dir = dir( $this->path );
        while( false !== ( $file = $dir->read() ) ) {
            if( $file != "." and $file != ".." and !is_dir( $file ) ) {
                if( $this->path != "." or $file != basename( __FILE__ ) ) {
                    if( preg_match( $this->ereg, $file ) ) {
                        file_put_contents( "{$this->path}/$file", preg_replace( $search, $replace,
                                            file_get_contents( "{$this->path}/$file" ) ) );
                    }
                }
            }
        }
        $dir->close();
    }
}

$files = new replaceFiles( "." );

$files->ereg( "/.txt$/" );

$files->replace( "/123/", "456" );

?>

Последний раз редактировалось smap; 07.06.2006 в 18:54.
smap вне форума