search

BOM: Byte Order Mark UTF-8 BOM is also called UTF-8 signature. In fact, the BOM of UTF-8 has no effect on UFT-8. It is added to support UTF-16 and UTF-32. The meaning of BOM signature is It just tells the editor what encoding the current file uses to facilitate the editor's identification. However, although the BOM is not displayed in the editor, it will produce output, just like an extra blank line. If you modify any PHP file, it will happen: Unable to log in or log out; * A blank line appears at the top of the page; * An error warning appears at the top of the page; Other abnormal situations. It's probably an editor problem. This program uses UTF-8 encoding. Almost all text editing software now can display and edit UTF-8 encoded files. But unfortunately, many of them don't perform well. Software such as Notepad that comes with WINDOWS will insert three invisible characters (0xEF 0xBB 0xBF, or BOM) at the beginning of the file when saving a file encoded in UTF-8. It is a string of hidden characters used to let editors such as Notepad identify whether the file is encoded in UTF-8. For ordinary files, this will not cause any trouble. But for PHP, BOM is a problem. PHP does not ignore the BOM, so when reading, including or referencing these files, the BOM will be used as part of the beginning text of the file. According to the characteristics of embedded languages, this string of characters will be executed (displayed) directly. As a result, even if the top padding of the page is set to 0, the entire web page cannot be placed close to the top of the browser, because there are these 3 characters at the beginning of the html! The biggest trouble is not this. Due to the limitations of the COOKIE sending mechanism, in files that already have a BOM at the beginning of these files, the COOKIE cannot be sent (because PHP has already sent the file header before the COOKIE is sent), so the login and logout functions are invalid. All functions that rely on COOKIE and SE SSION are invalid. Therefore, when editing or changing any text file, be sure to use an editor that does not add BOM randomly. Editors under Linux should not have this problem. Under WINDOWS, please do not use editors such as Notepad. The recommended editors are: Editplus version 2.12 or above; EmEditor; UltraEdit (the relevant options of 'Add BOM' need to be cancelled); Dreamweaver (the relevant options of 'Add BOM' need to be cancelled), etc. For files that have added BOM, if you want to cancel, you can use the above editor to save it once. (Editplus needs to save as gb first, and then save as UTF-8.) , the following is the program solution:

[PHP] code

  1. $auto = 1;
  2. checkdir('C:projectweibo');
  3. function checkdir($basedir){
  4. if ($dh = opendir($basedir)) {
  5. while (( $file = readdir($dh)) !== false) {
  6. if($file{0} == '.')
  7. {
  8. continue;
  9. }
  10. if ($file != '.' && $file ! = '..'){
  11. if (!is_dir($basedir."/".$file)) {
  12. echo "filename: $basedir/$file ".checkBOM("$basedir/$file")." < ;br>";
  13. }else{
  14. $dirname = $basedir."/".$file;
  15. checkdir($dirname);
  16. }
  17. }
  18. }
  19. closedir($dh);
  20. }
  21. }
  22. function checkBOM ($filename) {
  23. global $auto;
  24. $contents = file_get_contents($filename);
  25. $charset[1] = substr($contents, 0, 1);
  26. $charset[2] = substr($contents, 1, 1);
  27. $charset[3] = substr($contents, 2, 1);
  28. if (ord($charset[1]) == 239 && ord($charset[2]) == 187 && ord ($charset[3]) == 191) {
  29. if ($auto == 1) {
  30. $rest = substr($contents, 3);
  31. rewrite ($filename, $rest);
  32. return ("BOM found, automatically removed.");
  33. } else {
  34. return ("BOM found.");
  35. }
  36. }
  37. else return ("BOM Not Found.");
  38. }
  39. function rewrite ($filename, $data) {
  40. $filenum = fopen($filename, "w");
  41. flock($filenum, LOCK_EX);
  42. fwrite( $filenum, $data);
  43. fclose($filenum);
  44. }
  45. ?>
Copy code
PHP, BOM


Statement
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
11 Best PHP URL Shortener Scripts (Free and Premium)11 Best PHP URL Shortener Scripts (Free and Premium)Mar 03, 2025 am 10:49 AM

Long URLs, often cluttered with keywords and tracking parameters, can deter visitors. A URL shortening script offers a solution, creating concise links ideal for social media and other platforms. These scripts are valuable for individual websites a

Working with Flash Session Data in LaravelWorking with Flash Session Data in LaravelMar 12, 2025 pm 05:08 PM

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

Build a React App With a Laravel Back End: Part 2, ReactBuild a React App With a Laravel Back End: Part 2, ReactMar 04, 2025 am 09:33 AM

This is the second and final part of the series on building a React application with a Laravel back-end. In the first part of the series, we created a RESTful API using Laravel for a basic product-listing application. In this tutorial, we will be dev

Simplified HTTP Response Mocking in Laravel TestsSimplified HTTP Response Mocking in Laravel TestsMar 12, 2025 pm 05:09 PM

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

cURL in PHP: How to Use the PHP cURL Extension in REST APIscURL in PHP: How to Use the PHP cURL Extension in REST APIsMar 14, 2025 am 11:42 AM

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

12 Best PHP Chat Scripts on CodeCanyon12 Best PHP Chat Scripts on CodeCanyonMar 13, 2025 pm 12:08 PM

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

Announcement of 2025 PHP Situation SurveyAnnouncement of 2025 PHP Situation SurveyMar 03, 2025 pm 04:20 PM

The 2025 PHP Landscape Survey investigates current PHP development trends. It explores framework usage, deployment methods, and challenges, aiming to provide insights for developers and businesses. The survey anticipates growth in modern PHP versio

Notifications in LaravelNotifications in LaravelMar 04, 2025 am 09:22 AM

In this article, we're going to explore the notification system in the Laravel web framework. The notification system in Laravel allows you to send notifications to users over different channels. Today, we'll discuss how you can send notifications ov

See all articles

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 agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools