How to remove the bom header in php: 1. Use the "json_decode($result, true)" method to achieve removal; 2. Use "@iconv("UTF-8", "GBK//IGNORE", $ result);" to remove the BOM header.
Recommendation: "PHP Video Tutorial"
PHP method to remove BOM header
But PHP did not consider the BOM header problem at the beginning of the design, so it is easy to have problems during encoding and decoding
For example, the problem encountered today, json_decode , when the decoded string has a BOM header, json_decode fails to parse and returns NULL. (Why not automatically detect and remove the BOM header... small complaint)
I tried two ways to remove it:
$result = trim($result, "\xEF\xBB\xBF"); print_r(json_decode($result, true)); exit;
There is another kind that is more reserved:
$result = @iconv("UTF-8", "GBK//IGNORE", $result); $result = @iconv("GBK", "UTF-8//IGNORE", $result); print_r(json_decode($result, true)); exit;
The above is the detailed content of How to remove bom header in php. For more information, please follow other related articles on the PHP Chinese website!