PHP Bulk Removal BOM Header code sharing _php Tutorial

Source: Internet
Author: User

PHP Batch removal BOM header code sharing


This article mainly introduces the PHP batch removal BOM Header code sharing, this article directly give the implementation code, the code is relatively simple, easy to understand, the need for friends can refer to the next

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21st

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

/**

* Removal of BOM header information

*/

Header ("content-type:text/html; Charset=utf-8 ");

$auto = 1;

Checkdir ("D:\wamp\www\sales");

function Checkdir ($basedir) {

if ($dh = Opendir ($basedir)) {

while (($file = Readdir ($DH))!== false) {

if ($file! = '. ' && $file! = ' ... ') {

if (!is_dir ($basedir. " /". $file)) {

echo "File name: $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 ("Found BOM and deleted automatically");

} else {

Return ("Discovery BOM");

}

}

else return ("No BOM found");

}

function rewrite ($filename, $data) {

$filenum = fopen ($filename, "w");

Flock ($filenum, LOCK_EX);

Fwrite ($filenum, $data);

Fclose ($filenum);

}

?>

http://www.bkjia.com/PHPjc/1022062.html www.bkjia.com true http://www.bkjia.com/PHPjc/1022062.html techarticle php Bulk Removal BOM Header code sharing this article mainly introduces the PHP batch removal BOM Header code sharing, this article directly give the implementation code, code is relatively simple, easy to understand, the need for friends can participate ...

  • 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.