note 104151 added to function.pack
| From: | Gerjoo at gmail dot com | Date: | Thu, 26 May 2011 19:55:10 +0000 |
| Subject: | note 104151 added to function.pack | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-180063@lists.php.net to get a copy of this message | ||
You can use pack to strip the byte order mark (BOM) from a file.
For example, strip the UTF-8 BOM:
<?php
// Strips the UTF-8 mark: (hex value: EF BB BF)
function trimUTF8BOM($data){
if(substr($data, 0, 3) == pack('CCC', 239, 187, 191)) {
return substr($data, 3);
}
return $data;
}
?>
This function could be easily adjusted to match any byte order mark. Have a look at wikipedia for a
full list of hex codes for each specific encoding.
- Gerard
----
Server IP: 91.199.167.223
Probable Submitter: 83.87.181.228
----
Manual Page -- http://www.php.net/manual/en/function.pack.php
Edit -- https://master.php.net/note/edit/104151
Del: integrated -- https://master.php.net/note/delete/104151/integrated
Del: useless -- https://master.php.net/note/delete/104151/useless
Del: bad code -- https://master.php.net/note/delete/104151/bad+code
Del: spam -- https://master.php.net/note/delete/104151/spam
Del: non-english -- https://master.php.net/note/delete/104151/non-english
Del: in docs -- https://master.php.net/note/delete/104151/in+docs
Del: other reasons-- https://master.php.net/note/delete/104151
Reject -- https://master.php.net/note/reject/104151
Search -- https://master.php.net/manage/user-notes.php