Table of Contents
Invisible character 65279 (utf-8 BOM header) problem in php, 65279bom
The problem of PHP program UTF8 without BOM, please enlighten me
When encoding php files with utf-8, we can choose to use (utf-8 encoding format) or (utf-8 no BOM encoding format)
Home Backend Development PHP Tutorial Invisible character 65279 (BOM header of utf-8) problem in PHP, 65279bom_PHP tutorial

Invisible character 65279 (BOM header of utf-8) problem in PHP, 65279bom_PHP tutorial

Jul 13, 2016 am 10:20 AM
php php file utf-8

Invisible character 65279 (utf-8 BOM header) problem in php, 65279bom

Today on CSDN I saw a problem with PHP outputting the blank invisible character 65279. I looked it up on the Internet and found that the 65279 character is used by PHP to mark the file as UTF-8 encoded. When outputting, it will be output to the client together. end, causing the client to be unable to match the string when using ajax to get the return value.

php invisible character 65279 is explained as follows:

UTF-8 encoded files can be divided into two formats: no BOM and BOM.

What is BOM?

 "EF BB BF" These three bytes are called BOM, and the full name is "Byte Order Mard". BOM is commonly used in utf8 files to indicate that the file is a UTF-8 file, and the original intention of BOM is to be used in utf16.

When a UTF-8 file is output in PHP, BOM will be output, so to use UTF-8 in PHP, you must use a UTF-8 file without BOM header.

Commonly used text editing software supports different ways of saving UTF-8 files, so you should pay special attention when using them.

For example:

1. When using ultraedit, there are two options: "UTF-8" and "UTF-8 - No BOM" when saving.
2. The notepad in window saves the file with BOM.
3. Different versions of EditPlus software have different support for saving UTF-8. For example: version 2.31 saves without BOM, and version 2.11 saves with BOM.

How to remove the utf-8 file header:

1. Use ultraedit to save as "UTF-8 - No BOM"
2. A very useful PHP program, run in the root directory of the site, will remove the BOM headers of all UTF-8 files in the directory. The code is as follows:

//remove the utf-8 boms 
 //by magicbug at gmail dot com 
  
 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")." <br>"; 
         }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 ("<font color=red>BOM found, automatically removed.</font>"); 
     } else { 
       return ("<font color=red>BOM found.</font>"); 
     } 
   } 
   else return ("BOM Not Found."); 
 } 
  
 function rewrite ($filename, $data) {
   $filenum = fopen($filename, "w"); 
   flock($filenum, LOCK_EX); 
   fwrite($filenum, $data); 
   fclose($filenum); 
} 
Copy after login

The problem of PHP program UTF8 without BOM, please enlighten me

First, BOM will not affect the decoding you display...
If you manually decode, it will work normally. That's because you didn't specify the string encoding in your file
header("Content-type: text/html;charset=utf8"); add this sentence
at the beginning of the PHP file

When encoding php files with utf-8, we can choose to use (utf-8 encoding format) or (utf-8 no BOM encoding format)

When saving, use UTF-8 BOM-free encoding format.

When PHP processes the BOM header, sometimes there are errors, which may cause an error that the file has been output when you use functions such as header or session_start. Most of the time it is because the BOM header is sent out. . Because in php's view, it becomes a space. So use BOM-free format!

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/864933.htmlTechArticleInvisible character 65279 (utf-8 BOM header) problem in php, 65279bom I saw a php output in CSDN today I looked up the problem of the blank invisible character 65279 on the Internet and found that the 65279 character was sent by PHP...
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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

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)

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

To work on file upload we are going to use the form helper. Here, is an example for file upload.

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

In this chapter, we are going to learn the following topics related to routing ?

CakePHP Working with Database CakePHP Working with Database Sep 10, 2024 pm 05:25 PM

Working with database in CakePHP is very easy. We will understand the CRUD (Create, Read, Update, Delete) operations in this chapter.

CakePHP Creating Validators CakePHP Creating Validators Sep 10, 2024 pm 05:26 PM

Validator can be created by adding the following two lines in the controller.

See all articles