Write to file using Hex

Posted on 2011-10-31
Medium Priority
Last Modified: 2012-05-12
Is it possible to write to a file in PHP using HEX?

I have a HEX string, which needs to be written back into a file.

Any ideas?

Thank you
Question by:tonelm54
  • 3
LVL 111

Expert Comment

by:Ray Paseur
ID: 37056556
Yes, it's possible.  String variables can have any kind of data.
LVL 111

Expert Comment

by:Ray Paseur
ID: 37056558
If you want to post the hex string, I will be glad to show you how it can work.
LVL 34

Expert Comment

ID: 37060693
greetings tonelm54, , HEX is just a string that only has 16 letters and numbers in it, using only = "abcdef1234567890", so your question does not make much sense as "Is it possible to write to a file in PHP using HEX?"
Can you explain what your problem is with more information, have you written to a file before, do you need PHP methods to write to file, or what is it in PHP that you need information about? ?

Accepted Solution

liveaspankaj earned 2000 total points
ID: 37061527

$fh = fopen("filename.txt", "w");
fwrite($fh, $hexstringvariable);

filename.txt should be writable
LVL 111

Expert Comment

by:Ray Paseur
ID: 37093251
The accepted solution cannot possibly work because it has no "start PHP" tag and it uses an undefined variable.  You might want to get some foundation in how PHP works.  These are two learning resources that will help you get started.

Fortunately for all of us, the PHP functions are well-documented in the online man pages.  You can see the fwrite() example in the link below.  It is worth reading carefully.  Note that fwrite() provides return values.  You cannot just call fwrite() and assume that it wrote something.  You must test the return values from fwrite() to know whether it worked or not.  You might also want to read the notes carefully.  One of the notes says, On systems which differentiate between binary and text files (i.e. Windows) the file must be opened with 'b' included in fopen() mode parameter..  This is why I asked you to post the data you are working with (ID:37056558).  Sometimes at EE you will get an answer that has not been tested and may not be well-thought-out.  Caveat Emptor.

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses
Course of the Month17 days, 2 hours left to enroll

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question