


Invisible character 65279 (BOM header of utf-8) problem in PHP, 65279bom_PHP tutorial
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); }
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 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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

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

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

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

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

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

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

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

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