Sometimes, we want to remove multiple UTF-8 BOM sequences with PHP.
In this article, we’ll look at how to remove multiple UTF-8 BOM sequences with PHP.
How to remove multiple UTF-8 BOM sequences with PHP?
To remove multiple UTF-8 BOM sequences with PHP, we can use the preg_replace
function.
For instance, we write
function remove_utf8_bom($text)
{
$bom = pack("H*", "EFBBBF");
$text = preg_replace("/^$bom/", "", $text);
return $text;
}
to define the remove_utf8_bom
function that replaces the regex that starts with the BOM sequence with empty strings in the $text
string.
Then we return the $text
srring.
Conclusion
To remove multiple UTF-8 BOM sequences with PHP, we can use the preg_replace
function.