I thought that some of you might find it useful to learn how to generate a string with random numbers and letters. I wrote a quick function for generating a string like this. See it below :
Mon, Oct 1, 2007
I thought that some of you might find it useful to learn how to generate a string with random numbers and letters. I wrote a quick function for generating a string like this. See it below :
August 3rd, 2008 at 1:39 pm
Nice, came across this with a quick google search.
You have some syntax incorrect though. As it is now it will return something like 1f’q4w’432″2 - You don’t want those odd characters in there right?
Remove $string = “; it will get defined anyway. Also replace the ‘ around the $characters declaration and replace it with ” - it should look like this:
$characters = “0123456789abcdefghijklmnopqrstuvwxyz”;
That will mean the return will only have letters and numbers
August 3rd, 2008 at 1:54 pm
Hi Jake,
Thank you for the comment.
It is the encoding of Wordpress which causes those entities.
In reality, you have to replace them with proper html characters when you use the code. Here is a sample :
http://lost-in-code.com/wp-content/_randomstring.php
It works well.
All the best,
Antonie
August 7th, 2008 at 5:07 pm
Oh then I do apolosgize! Didn’t consider WP might be screwing things up.
But thank you for the snippet there. I used it in http://www.jakeisonline.com/s/ - something I was working on for work.
Thanks!
August 31st, 2008 at 11:58 am
Also found this via google. Nice function, just wanted to drop a line and say thanks, I used this for my blog.
September 11th, 2008 at 10:21 pm
Thanks for the clip, nice and clean!
-Ryan
September 27th, 2008 at 1:06 am
Shouldn’t it be strlen()-1 instead of strlen()?
mt_rand() will sometimes return int $max and there isn’t a proper value in $characters[strlen()]
October 17th, 2008 at 5:47 am
Great, thanks.