Write to file using Hex

Posted on 2011-10-31
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
    LVL 107

    Expert Comment

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

    Expert Comment

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

    Expert Comment

    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? ?
    LVL 5

    Accepted Solution


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

    filename.txt should be writable
    LVL 107

    Expert Comment

    by:Ray Paseur
    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

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    Part of the Global Positioning System A geocode ( is the major subset of a GPS coordinate (, the other parts being the altitude and t…
    Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
    The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

    729 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

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now