Home php教程 php手册 thinkphp清除BOM方法

thinkphp清除BOM方法

Jun 07, 2016 am 11:36 AM
Do not show

在utf-8编码文件中BOM在文件头部,占用三个字节,用来标示该文件属于utf-8编码,现在已经有很多软件识别bom头,但是还有些不能识别bom头,比如PHP就不能识别bom头,这也是用记事本编辑utf-8编码后执行就会出错的原因了。BOM只有在WINDOWS下采用“记事本”存储为UTF-8时才会有,这个可以用WINHEX把开始的2个字节删掉。在dreamweaver里面编码设置里面可以设置是否带BOM,一般只要php输出的不是图片(GDI Stream),BOM都不会导致问题。GDI Stream如果开
去掉bom头的办法,简单的是下面两种:
1、editplus去BOM头的方法
编辑器调整为UTF8编码格式后,保存的文件前面会多出一串隐藏的字符(也即是BOM),用于编辑器识别这个文件是否是以UTF8编码。运行Editplus,点击工具,选择首选项,选中文件,UTF-8标识选择 总是删除签名,然后对PHP文件编辑和保存后的PHP文件就是不带BOM的了。
2、ultraedit去除bom头办法
打开文件后,另存为选项的编码格式里选择(utf-8 无bom头),确定就ok了。
对于PHP程序需要去除Bom头的也可以使用目录下的92wcms.php程序去除。

请用一下代码运行一次



if(isset($_GET['dir'])){ //config the basedir


$basedir=$_GET['dir'];


}else{


$basedir= '.';


}


$auto= 1;


checkdir($basedir);


function checkdir($basedir){


if($dh= opendir($basedir)) {


while(($file= readdir($dh)) !== false) {


if($file!= '.'&& $file!= '..'){


if(!is_dir($basedir."/".$file)) {


echo"filename: $basedir/


$file".checkBOM("$basedir/$file")."
";


}else{


$dirname= $basedir."/".


$file;


checkdir($dirname);


}


}


}


closedir($dh);


}


}


function checkBOM ($filename) {


global$auto;


$contents= file_get_contents($filename);


$charset[1] = substr($contents, 0, 1);


$charset[2] = substr($contents, 1, 1);


$charset[3] = substr($contents, 2, 1);


if(ord($charset[1]) == 239 && ord($charset[2]) == 187 && ord($charset[3]) == 191) {


if($auto== 1) {


$rest= substr($contents, 3);


rewrite ($filename, $rest);


return("BOM found,automatically removed.");


} else{


return("BOM found.");


}


}


else return("BOM Not Found.");


}


function rewrite ($filename, $data) {


$filenum= fopen($filename, "w");


flock($filenum, LOCK_EX);


fwrite($filenum, $data);


fclose($filenum);


}


?>


附件 92wcms.rar ( 692 B 下载:17 次 )

AD:真正免费,域名+虚机+企业邮箱=0元

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

The USB disk does not show up on my computer The USB disk does not show up on my computer Feb 11, 2024 pm 01:51 PM

Many students often fail to pop up the USB flash drive normally when using it. Instead, they unplug it directly, causing the drive letter not to be displayed. The following will teach friends how to solve it: Step 1: Select the win icon in the lower left corner of the desktop and select the number one from the bottom. Two setting options. Step 2: Select device options. Step 3: Find other devices and find the USB flash drive icon. If you don’t recognize it, don’t panic. Just stay on this interface and you can find it by plugging in the USB flash drive. Step 4: Remove the device from the stand-alone USB flash drive icon, and plug the USB flash drive again and the drive letter will be displayed. If it helped you, please like it and encourage me to solve more computer problems for you. This is an article updated by the trial version of Shuimiao·dedeCMS station group article updater, so it has this mark (2023-02-0617:27:18)

Solution to Win7 picture thumbnail not displaying Solution to Win7 picture thumbnail not displaying Jan 07, 2024 pm 12:45 PM

When we view pictures, we only need to roughly see the thumbnail of each picture in the folder, so that we can quickly browse or find the pictures we need. However, sometimes image thumbnails are not displayed. It may be due to settings or insufficient memory. The specific solutions are as follows. Win7 picture thumbnails are not displayed. Solution Method 1: 1. First, select "Organize" in the upper left corner of the folder, and then click "Folder and Search Options". 2. Uncheck "Always show icons, never thumbnails" and click OK. Method 2: 1. First check whether your C drive still has enough space, at least 1GB or more. 2. If not, right-click the C drive and select Properties, then click "Disk Cleanup" in "General". 3.

How to solve the problem that the recycle bin is not displayed in win11 How to solve the problem that the recycle bin is not displayed in win11 Dec 26, 2023 pm 09:47 PM

All useless files and garbage on the computer are stored in the recycle bin. Many users find that their recycle bin is gone after updating the win11 system, resulting in the inability to restore the required files. For this reason, we will bring it to you today. Come and find out how to solve the problem of Win11 not displaying the Recycle Bin. What to do if the Recycle Bin is not displayed in Windows 11? 1. First, right-click the mouse on a blank area of ​​the desktop and select the "Personalize" option in the pop-up menu. 2. After selection, a settings interface will appear. Find the theme option on the left side of the settings interface and click it. 3. After clicking, scroll down on the right side to find and click the "Desktop Icon Settings" option. 4. After clicking, you can see the recycle bin selection interface. 5. Check the Recycle Bin and click OK to restart

Learn about introductory code examples for Python programming Learn about introductory code examples for Python programming Jan 04, 2024 am 10:50 AM

Learn about Python programming with introductory code examples Python is an easy-to-learn, yet powerful programming language. For beginners, it is very important to understand the introductory code examples of Python programming. This article will provide you with some concrete code examples to help you get started quickly. Print HelloWorldprint("HelloWorld") This is the simplest code example in Python. The print() function is used to output the specified content

Go language programming examples: code examples in web development Go language programming examples: code examples in web development Mar 04, 2024 pm 04:54 PM

"Go Language Programming Examples: Code Examples in Web Development" With the rapid development of the Internet, Web development has become an indispensable part of various industries. As a programming language with powerful functions and superior performance, Go language is increasingly favored by developers in web development. This article will introduce how to use Go language for Web development through specific code examples, so that readers can better understand and use Go language to build their own Web applications. 1. Simple HTTP Server First, let’s start with a

The CAD font library is imported but still not displayed. The CAD font library is imported but still not displayed. Feb 20, 2024 pm 09:42 PM

In CAD software, the import of font libraries is very important for displaying correct text. However, sometimes even if the font library is successfully imported, the text still cannot be displayed, which can often be confusing and frustrating. This article will explore some common issues that may cause CAD software to fail to display fonts and provide solutions. 1. The font library format is not supported. CAD software usually has its own supported font format. If the imported font library format is not supported, the text will not be displayed correctly. Before importing the font library, you should first ensure that the font format is CAD

PHP variables in action: 10 real-life examples of use PHP variables in action: 10 real-life examples of use Feb 19, 2024 pm 03:00 PM

PHP variables store values ​​during program runtime and are crucial for building dynamic and interactive WEB applications. This article takes an in-depth look at PHP variables and shows them in action with 10 real-life examples. 1. Store user input $username=$_POST["username"];$passWord=$_POST["password"]; This example extracts the username and password from the form submission and stores them in variables for further processing. 2. Set the configuration value $database_host="localhost";$database_username="username";$database_pa

Java implements simple bubble sort code Java implements simple bubble sort code Jan 30, 2024 am 09:34 AM

The simplest code example of Java bubble sort Bubble sort is a common sorting algorithm. Its basic idea is to gradually adjust the sequence to be sorted into an ordered sequence through the comparison and exchange of adjacent elements. Here is a simple Java code example that demonstrates how to implement bubble sort: publicclassBubbleSort{publicstaticvoidbubbleSort(int[]arr){int

See all articles