Php stealth character 65279 (BOM header of UTF-8), 65279bom_PHP tutorial

Source: Internet
Author: User
Tags ultraedit
65279 invisible character in php (BOM header of UTF-8), 65279bom. Php stealth character 65279 (BOM header of UTF-8) problem, 65279bom today in CSDN saw a php output blank invisible character 65279 problem, found on the Internet, this 65279 character is an invisible character 65279 (UTF-8 BOM header) in php, 65279bom

Today, I saw a problem with php output of a blank invisible character 65279 in CSDN. I found it online and sent the 65279 character that php used to mark the file as UTF-8 encoded, the output will be output to the client together, causing the client to fail to match the string if ajax is used to obtain the return value.

Php stealth character 65279 is explained as follows:

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

What is BOM?

"Ef bb bf" these three bytes are called BOM, full name is "Byte Order Mard ". In utf8 files, BOM is often used to indicate that this file is a UTF-8 file, and BOM is intended to be used in utf16.

The bom is output when the UTF-8 file is output in php. therefore, to use UTF-8 in php, you must use a UTF-8 file without the bom header.

The commonly used text editing software supports UTF-8 file storage in different ways. pay special attention when using it.

For example:

1. when you use ultraedit, there are two options for "UTF-8" and "UTF-8-no BOM" when you save it.
2. Windows Notepad stores bom.
3. different versions of the EditPlus software support different UTF-8 storage features. for example, Version 2.31 saves data without bom and version 2.11 saves data with bom.

Remove the UTF-8 file header:

1. use ultraedit to save, select "UTF-8-no BOM"
2. a very useful php program running 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")." 
"; }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); }


PHP program UTF8 has no BOM problem, please kindly advise

First, BOM will not affect your display of the verification code ......
If you manually confirm the code, it will work properly. That's because you didn't specify 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 select (UTF-8 encoding format) or (UTF-8 without BOM encoding format)

When saved, use the UTF-8 without BOM encoding format.

Php sometimes has errors when processing BOM headers, which may cause output errors when you use functions such as header or session_start, most of them are sent out by BOM headers .. In php, it is a space. Therefore, the BOM-free format is used!

Coding (UTF-8 BOM header) problem, 65279bom today in CSDN saw a php output blank invisible character 65279 problem, found on the internet, send this 65279 character is for php...

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.