Skip to content

Instantly share code, notes, and snippets.

@asvae
Created May 23, 2016 14:27
Show Gist options
  • Save asvae/801378550cb4310a6390c65806142aec to your computer and use it in GitHub Desktop.
Save asvae/801378550cb4310a6390c65806142aec to your computer and use it in GitHub Desktop.
Baldr sky manual converter
<?php
use League\Flysystem\Adapter\Local;
use League\Flysystem\Filesystem;
require_once($_SERVER["DOCUMENT_ROOT"] . '/autoload/bootstrap.php');
$path = 'baldr_sky_manual/manual';
$dir = new Filesystem(new Local($_SERVER["DOCUMENT_ROOT"]));
$files = $dir->listContents($path, true);
$files = collect($files)->where('extension', 'htm');
foreach ($files as $file) {
$newPath = "baldr_sky_manual/manual_converted/{$file['basename']}l";
$contents = $dir->read($file['path']);
$contents = mb_convert_encoding($contents, 'UTF-8', 'SJIS');
$contents = trim($contents);
$contents = str_replace('<html>', '<!doctype html><html lang="jp">', $contents);
$contents = str_replace('<head>', '<head><meta charset="UTF-8">', $contents);
$dir->put($newPath, $contents);
}
dd('Okay!');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment