Base 64 detection



  • How do i detect base64 encoded string in a varable in PHP4



  • @jrwr00 said:

    How do i detect base64 encoded string in a varable in PHP4

    Well, Base 64 encoding has a fairly fixed format, so if the input string matches that format then it's a base-64 encoded string.  Whether it encodes anything useful is another matter. The format is laid out in RFC 1421 and explained in more detail in RFCs 3548 and 4648.  I suggest reading those documents; they're short and google knows where they are.

    More generally, though, why do you need to detect whether something is encoded in base-64?  You know what the input is at one stage, so you must be losing that information somewhere in your code.  Go back to where you gather the string that "might" be base64 and record whether it is or not -- then you don't need to detect it, you just consult that record (variable, object field, type, some other bit of information).

    Edit: 100th post.
     


Log in to reply