Removing Byte Order Mark (BOM) from the given string.

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.

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));
*/

Leave a Reply