在PHP中打印您姓名中的随机字母[重复]

This question already has an answer here:

I just start to learn PHP, but I can't to make a easy problem. Can you help me and after say why my problem doesn't work? Here is the problem:

  1. Create a new variable $name and store your name in it.
  2. Then print a random character from your name. Use your knowledge of strlen(string), rand(min, max), and substr(string, start, length) to do this.

HINT: Remember that substr() treats characters in a string as a zero-indexed array (first letter is at position zero). This means that the last character in the string will be at position length - 1.

I try but without result.

<html>
    <p>
    <?php
    $name = "George";
    $fl = substr($name, 0, strlen($name));
    $sl = substr($name, 0, 1);
    print rand($fl,$sl);
    ?>
    </p>
</html>

I think problem is at rand...I can't randomise items with id or something?I can print the $sl or $fl ..

</div>

It can be done like this:

<?php
$name = "George";
$nameLength = strlen($name);
$randomNumber = rand(0, $nameLength - 1);
$randomLetter = substr($name, $randomNumber, 1);
echo $randomLetter;
?>

Source: https://stackoverflow.com/a/23915981/5798798