sgvsv/php-mass-files-converter

将指定目录下的文件从指定编码转换为UTF-8

v1.0 2019-09-03 14:20 UTC

This package is auto-updated.

Last update: 2024-08-29 06:01:39 UTC


README

将指定目录下的文件从指定编码递归转换为UTF。类会检查每个文件是否已经是UTF编码。如果是,则不会进行双重转换。可以设置要转换的文件扩展名。还可以排除一些子目录以避免转换。

需求

为了提供现代PHP功能,如方法签名中设置类型,需要PHP7.1或更高版本。

安装

最好通过composer安装此库

composer require sgvsv/php-mass-files-converter

使用示例

安装后,您可以转换文件

require_once __DIR__ . '/vendor/autoload.php';

use \sgvsv\FilesConverter\Converter;

//Argument is a directory to convert
//c:\\my\\dir in windows or /path/to/dir in linux
$converter = new Converter("c:\\my\\dir");

//Files with /vendor/ or /.git/ substrings in their paths will be ignored
$converter->setIgnoredPaths(['/vendor/', '/.git/']);

//Files with other extensions will be ignored
$converter->setExtensions(['txt', 'php']);

//Output list of files and detected encodings
echo $converter->preview();

//Files that wasn't in UTF will be replaced with converted files
//File that already was in UTF will not be changed
$converter->convert();