Bom is a headache. Many problems are caused by garbled code generated during php development. This tool has been found on the Internet and has been optimized by myself, making it easier to use. if you need it, please feel free to use it without any side effects.
CodeAs follows:
<? Phpheader ("Content-Type: text/html; charset = UTF-8"); If (isset ($ _ Get ['dir']) {// set the file directory $ basedir =$ _ Get ['dir'];} else {$ basedir = '. ';}$ auto = 1; checkdir ($ basedir); function checkdir ($ basedir) {if ($ DH = opendir ($ basedir )) {While ($ file = readdir ($ DH ))! = False) {if ($ file! = '.' & $ File! = '..') {If (! Is_dir ($ basedir. "/". $ file) {echo "File Name: $ basedir/$ File ". checkbom ("$ basedir/$ File "). "<br>";} else {$ dirname = $ basedir. "/". $ file; checkdir ($ dirname) ;}} closedir ($ DH) ;}} function checkbom ($ filename) {Global $ auto; $ contents = file_get_contents ($ filename ); $ charset [1] = substr ($ contents, 0, 1); $ charset [2] = substr ($ contents, 1, 1 ); $ charset [3] = substr ($ contents, 2, 1); If (ord ($ charset [1]) = 239 & Ord ($ charset [2]) = 187 & ord ($ charset [3]) = 191) {if ($ auto = 1) {$ rest = substr ($ contents, 3); rewrite ($ filename, $ rest ); return ("<font color = Red> BOM found and deleted automatically </font> ");} else {return ("<font color = Red> BOM found </font>") ;}} else return ("Bom not found");} function rewrite ($ filename, $ data) {$ filenum = fopen ($ filename, "W"); flock ($ filenum, lock_ex); fwrite ($ filenum, $ data ); fclose ($ filenum) ;}?>