Blank line problem caused by PHP reference file (UTF-8) _php Tutorial

Source: Internet
Author: User
There may be a lot of people come across in PHP if it is UTF8 encoding we import the file will appear blank line problem, below I will give you the reference file blank line solution.

A reference file refers to a blank line that is caused by an include, require_once reference to another file

This is actually you use Notepad to edit UTF-8 file, although you still save as UTF-8 format, but the system will automatically add two BOM mark, but IE can only ignore one, the other is blank line.
The solution is:

Do not use Notepad to edit the UTF-8 file, use other tools, than DREAMW, EmEditor, Visual Studio 2008 and other editing tools to edit UTF-8 file after saving.

My two stations with Notepad edit the top of the blank line, initially thought to be a CSS setup problem, the result is BOM tag caused.

There is another way, if you are a lot of files so we can use a PHP function to fix

Copy the following code into a php file, and then put in the need to clear the BOM header of the directory run, you can batch the first line of PHP blank to clear out, too to force.

The code is as follows Copy Code


if (Isset ($_get[' dir ')) {//Set file directory
$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);
}
?>

http://www.bkjia.com/PHPjc/632081.html www.bkjia.com true http://www.bkjia.com/PHPjc/632081.html techarticle There may be a lot of people come across in PHP if it is UTF8 encoding we import the file will appear blank line problem, below I will give you the reference file blank line solution. Reference ...

  • Related Article

    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.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.