I’ve been using this to gender a random 12 character string:
// lost-in-code.com/programming/php-code/php-random-string-with-numbers-and-letters
$ch = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@$%^&(){}[]+=-_/?|*#";
$sc = "";
for ($p = 0; $p < 12; $p++) {
$sc .= $ch[mt_rand(0,82)]; // 83 is the strlen of characters
}
It turns out that it in practice it can include a space in the string. This was not expected!
Why would it be? Does it treat the underscore as a space? It’s been causing random (and until now, untraceable) bugs.
Thanks.
At a guess (not tested) change the quotes around the $ch string to single quotes. stops the braces from being “evaluated”
Edit:
Just to update after some testing – it’s NOT converting “as is” – so there’s something else in the code that’s causing problems. Just ran it over 100,000 times without spaces.
Still put as single quotes to rule that issue out (you may have other variables that are getting evaluated) but that alone is not the issue.
Danger characters are described here