#!/usr/bin/php
<?php

for ($i=1; $i<$argc; $i++) {

	$file = $argv[$i];

	if (!file_exists($file)) { echo "Skip (non existing) $file\n"; continue; }
	if (is_dir($file)) { echo "Skip (directory) $file\n"; continue; }

	$cont = file_get_contents($file);
	$cont_orig = $cont;

	//if (str_starts_with($cont,'<?php') || str_starts_with($cont,'#!/')) {
	$t = filemtime($file);
	system("iconv -f ISO-8859-1 -t UTF-8 ".escapeshellarg($file)." -o ".escapeshellarg($file));
	//}

	$cont = file_get_contents($file);
	if ($cont_orig != $cont) {
		echo "Fixed $file\n";
	} else {
		touch($file, $t);
	}

}
