PHP去除文件夹下所有文件中换行、空格字符

/**
 * @param string $path 文件夹路径
 */
function handle( string $path ) {
    $open = opendir( $path );

	$dir = [];
    while (($file = readdir($open)) !== false){
        $dir[] = $file;
    }

    closedir($open);

    for ($i=2;$i<=count($dir)-1;$i++){
        $str = file_get_contents( $path . '/' . $dir[$i] );

        $str = preg_replace( '/\n/' , '' , $str );

        $str = preg_replace( '/\r/' , '' , $str );

        $str = str_replace( '  ' , '' , $str );

        file_put_contents( $path . '/' . $dir[$i] , $str );
    }

    return 'success';
}

你可能感兴趣的:(文件处理)