Home > Article > Backend Development > How to remove bom header in php
The way to remove the bom header in php is: it can be achieved through the ltrim() function. The ltrim() function can remove whitespace characters or other predefined characters on the left side of a string. Specific usage: [$con=ltrim($con,"\XEF\XBB\XBF");].
#PHP can use the ltrim() function to remove the BOM header.
ltrim() function can remove whitespace characters or other predefined characters on the left side of a string.
Grammar format:
ltrim(string,charlist)
Code example:
<?php //用fopen函数打开1.php文件 $file=fopen("1.php","r") or die ("unable to open file"); //读取1.php文件内容 $con=fread($file,filesize("1.php")); //调用ltrim将1.php开头的BOM头去掉。 $con=ltrim($con,"\XEF\XBB\XBF"); //3.php文件 $newfile=fopen("3.php","w") or die ("unable to create file"); //通过fwrite命令将去掉BOM头的1.php文件的内容写入到3.php fwrite($newfile,$con); //关闭文件 fclose($newfile); fclose($file); ?>
If you want to know more, please visit php Chinese website.
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!