note 76358 added to function.file-get-contents

From: Date: Wed, 11 Jul 2007 21:38:51 +0000
Subject: note 76358 added to function.file-get-contents
Groups: php.notes 
Request: Send a blank email to php-notes+get-128393@lists.php.net to get a copy of this message
If you're having problems with binary and hex data: I had a problem when trying to read information from a ttf, which is primarily hex data. A binary-safe file read automatically replaces byte values with their corresponding ASCII characters, so I thought that I could use the binary string when I needed readable ASCII strings, and bin2hex() when I needed hex strings. However, this became a problem when I tried to pass those ASCII strings into other functions (namely gd functions). var_dump showed that a 5-character string contained 10 characters, but they weren't visible. A binary-to-"normal" string conversion function didn't seem to exist and I didn't want to have to convert every single character in hex using chr(). I used unpack with "c*" as the format flag to see what was going on, and found that every other character was null data (ordinal 0). To solve it, I just did str_replace(chr(0), "", $string); which did the trick. This took forever to figure out so I hope this helps people reading from hex data! ---- Server IP: 64.71.164.2 Probable Submitter: 207.136.246.146 ---- Manual Page -- http://www.php.net/manual/en/function.file-get-contents.php Edit -- https://master.php.net/note/edit/76358 Del: integrated -- https://master.php.net/note/delete/76358/integrated Del: useless -- https://master.php.net/note/delete/76358/useless Del: bad code -- https://master.php.net/note/delete/76358/bad+code Del: spam -- https://master.php.net/note/delete/76358/spam Del: non-english -- https://master.php.net/note/delete/76358/non-english Del: in docs -- https://master.php.net/note/delete/76358/in+docs Del: other reasons-- https://master.php.net/note/delete/76358 Reject -- https://master.php.net/note/reject/76358 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#128393) next »