To generate a string containing a random selection of both letters and numbers (i.e. an alphanumeric string) using PHP is pretty trivial. Essentially what we want to do is define a string containing all the characters we wish to use in the generated string. Then randomly select characters from the string and glue them all together until we get a random string of the desired length. Coded as a function, you get: Pretty simple, but quite useful actually.
Sometimes it comes in quite handy to strip out all the non-alphanumeric characters from a given string. Of course, we could just use a bog standard preg_replace with a valid regex to achieve this, though the result of doing this might result in a non-readable resulting string.
Given a registration code, or something important like that, which often contains information encoded in the alphanumeric string itself, it is sometimes quite useful to be able to simply strip out the letters from the string, leaving only the numeric part behind.
Given a registration code, or something important like that, which often contains information encoded in the alphanumeric string itself, it is sometimes quite useful to be able to simply strip out the numbers from the string, leaving only the letters behind.
Craig Lotter is an established web developer and application programmer, with strong creative urges (which keep bursting out at the most inopportune moments) and a seemingly insatiable need to love all things animated. Living in the beautiful coastal town of Gordon's Bay in South Africa, he games, develops, takes in animated fare, trains under whichever martial arts dojo is closest at the time, and for the most part, simply enjoys life with his amazing wife and daughter.
Oh, and he draws ever now and then too.
This is a collection of things that he has managed to find the time to scribble down since 2007.
Looking for Something?
Jump to Category: