Tuesday 26 December 2017

unicode - Remove multiple BOMs from a file

itemprop="text">

I am using a Javascript file that is a
concatenation of other JavaScript
files.



Unfortunately, the person who
concatenated these JavaScript files together did not use the proper encoding when
reading the file, and allowed a BOM for every single JavaScript file to get written to
the concatenated JavaScript
file.




Does anyone know a simple way
to search through the concatenated file and remove any/all BOM
markers?



Using PHP or a bash script for Mac OSX
would be great.


itemprop="text">
class="normal">Answer



See also:
href="https://stackoverflow.com/questions/1068650/using-awk-to-remove-the-byte-order-mark">Using
awk to remove the Byte-order mark



To
remove multiple BOMs from anywhere within a text file you can try something similar.
Just leave out the ^
anchor:



perl -e
's/\xef\xbb\xbf//;' -pi~
file.js



(This
edits the file in-place. But creates a backup
file.js~.)


No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...