Last active
December 31, 2015 18:10
-
-
Save JPry/f7b6179e8b583f3a71b5 to your computer and use it in GitHub Desktop.
Remove BOM from a given file. Includes error checking.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* A simple script to remove BOM from a given file. | |
* | |
* @author Jeremy Pry | |
*/ | |
if ( $argc < 2 ) { | |
echo "Please include a file to operate on!" . PHP_EOL; | |
die( 1 ); | |
} | |
$file = $argv[1]; | |
if ( ! file_exists( $file ) ) { | |
echo "File [{$file}] does not exist!" . PHP_EOL; | |
die( 2 ); | |
} | |
if ( ! is_writable( $file ) ) { | |
echo "Cannot write to file [{$file}]" . PHP_EOL; | |
die( 3 ); | |
} | |
if ( is_dir( $file ) ) { | |
echo "[{$file}] is a directory!" . PHP_EOL; | |
die(4); | |
} | |
file_put_contents( $file, str_replace( "\xef\xbb\xbf", '', file_get_contents( $file ) ) ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment