How to remove bom header in php

王林
Release: 2023-03-01 19:10:01
Original
2822 people have browsed it

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)
Copy after login

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);
?>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template