Home  >  Article  >  Backend Development  >  How to remove bom header in php

How to remove bom header in php

王林
王林Original
2020-06-30 15:01:072746browse

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");].

How to remove bom header in php

#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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:What is a php bom?Next article:What is a php bom?