473,404 Members | 2,213 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

how to retrieve all the ascii characters from a binary file.

Hi i have a binary file that i need to parse.
The situation is that i need all the ascii characters from that binary file, the way that is to be implemented should be very efficient as the binary files are big.
Is there a function in php that can do that or a php script that can do the work.
Thanks
Varun
Aug 7 '07 #1
7 2089
kovik
1,044 Expert 1GB
The situation is that i need all the ascii characters from that binary file
Look at ord(), chr(), and unpack().
Aug 7 '07 #2
Hi what i am using now is the regular expression.
But that doesnt seem to work.

my regular expresson is :
preg_match("/Description\x20\x02\x20\x16(.*)Q/",$content,$match).
but the expression doesnt seem to work with hexadecimal values.
Is there something wrong in this one?
Thanks
Varun
Aug 10 '07 #3
pbmods
5,821 Expert 4TB
Heya, Varun.

My recommendation would be to parse the string manually:
  • Create an empty target string.
  • For each character in the binary string:
    • Check its value with ord().
    • If it is a printable character, append it to the target string.
Aug 12 '07 #4
kovik
1,044 Expert 1GB
Hi what i am using now is the regular expression.
Why? unpack() is suited specifically for handling binary data. Are you not familiar with data types? They should give you the syntax for the CHAR type in the documentation for the pack() function.
Aug 12 '07 #5
Why? unpack() is suited specifically for handling binary data. Are you not familiar with data types? They should give you the syntax for the CHAR type in the documentation for the pack() function.
The data i am trying to parse is a video file that has information contained within. Could you tell me what query should i write in unpack so that all the relevant information (Clip Information) can be retrieved from the binary file?

I am very new to php and have never worked on a problem like that. Sorry if that sounds too stupid.
Thanks
Varun
Aug 13 '07 #6
jx2
228 100+
The data i am trying to parse is a video file that has information contained within. Could you tell me what query should i write in unpack so that all the relevant information (Clip Information) can be retrieved from the binary file?

I am very new to php and have never worked on a problem like that. Sorry if that sounds too stupid.
Thanks
Varun
its not as easy as unpack() i understand you want to read exif data from "video" file - in my knowledge there is no such function in php u need to handle binary data on your own
1. u need to know file format
2. u need to read specification of this file format
3. u need to write function which can read the data you need

well i know i didnt helped but i hope i gave you an idea of the problem

regards
jx2
Aug 14 '07 #7
kovik
1,044 Expert 1GB
The data i am trying to parse is a video file that has information contained within. Could you tell me what query should i write in unpack so that all the relevant information (Clip Information) can be retrieved from the binary file?
Hehe. I see the problem.

I am very new to php and have never worked on a problem like that. Sorry if that sounds too stupid.
Dealing with binary data is beyond regular programming, and if you are new to programming, I'm sure that it's safe to assume that you are almost completely inexperienced with binary data. Dealing with binary data is up there with ASM and disassembly, as you are dealing with the raw data instead of human-readable code.

Files have formats. It's usually in the style of "Header" then "Data." You have to be familiar with the file format and the data types in order to decipher which bits are what, and then you have to be familiar with the storage types in order to translate the data into a usable format. I've been planning on writing a tutorial for dealing with binary data in PHP, but the interest is low and the extent of work necessary to teach it is not.

If you'd really like to deal with file formats in PHP without having to learn anything in-depth about file formats, search GoogleCode, SourceForge, or PHPClasses for pre-made scripts and APIs that deal with the file format that you are after.
Aug 14 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Bernhard Hidding | last post by:
Hi, my program writes chars to an ascii file via ofstream. You can use "\n" for newline and "\t" for tab there, but is there any command that deletes the last char in the current ofstream? Thanks...
5
by: b.stewart | last post by:
I have only been using C++ for a few afternoons and i still get confused at nearly every line i type so maybe someone here can help me. Im trying to write a small program that can change a...
22
by: Sunner Sun | last post by:
Hi, all Since the OS look both ASCII and binary file as a sequence of bytes, is there any way to determine the file type except to judge the extension? Thank you!
5
by: Lenard Gunda | last post by:
hi! I have the following problem. I need to read data from a TXT file our company receives. I would use StreamReader, and process it line by line using ReadLine, however, the following problem...
3
by: JSM | last post by:
Hi, I am just trying to port an existing simple encryption routine to C#. this routine simply adds/substracts 10 ascii characters to each character in a text file (except quotes). The routine...
31
by: Claude Yih | last post by:
Hi, everyone. I got a question. How can I identify whether a file is a binary file or an ascii text file? For instance, I wrote a piece of code and saved as "Test.c". I knew it was an ascii text...
18
by: John | last post by:
Hi, I'm a beginner is using C# and .net. I have big legacy files that stores various values (ints, bytes, strings) and want to read them into a C# programme so that I can store them in a...
4
by: meendar | last post by:
Hi, I am having a character pointer which contains ascii values. i just want to convert all these ascii values to respective characters and again store it in another character pointer. ...
1
by: Vic | last post by:
I have a c program which writes mac address entries onto a text file. Text file when opened in vim looks like this index mac 1 ^@^@^Q^@^@^A ascii of (00.00.11.00.00.01) 2 ^@^@^Q^@^@^B...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.