Removing Byte Order Mark (BOM) from the given string.
Posted by Luracast on Jul 3, 2006 in Blog, Code, PHP | 0 comments
Since PHP does not recognize and ignore BOM in the loaded files, I wrote the following script to find and remove the BOM from the loaded string.
1 2 3 4 5 6 7 8
| function removeBOM($str=''){
if(<a href="http://www.php.net/strpos">strpos</a>($str, "»")==1)$str=<a href="http://www.php.net/substr">substr</a>($str, 3);
return $str;
}
/*
//Usage:-
$text = removeBOM(file_get_contents("myData.xml",true));
*/ |