Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Revisions

3 of 6
fixed code padding

PHP random string generator

I'm trying to create a randomized string in PHP, and I get absolutely no output with this:

<?php
function RandomString()
{
 $characters = ’0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ’;
 $randstring = '';
 for ($i = 0; $i < 10; $i++) {
 $randstring = $characters[rand(0, strlen($characters))];
 }
 return $randstring;
}
RandomString();
echo $randstring;
?>

What am I doing wrong?

Captain Lightning
  • 10.8k
  • 4
  • 22
  • 17
lang-php

AltStyle によって変換されたページ (->オリジナル) /