What is wrong with my code?? <html> <p> <?php echo rand(); ?> </p> <p> <?php $name = "Sudeep Sagar"; echo rand(0, 4); $num = rand(0, strlen($name)-1); echo substr($name, $num, 1); ?> </p> </html>
This line is not expected.
First, the rand() function must have a min and max.
For the second part,
first you need to count the number of string of your name using strlen function, then use
the rand function, rand(0, $length)
then, you can now proceed to the substr function, substr(name, randomized number from your name, 1)
then there you have it.
rand() will output an integer in the range of 0 to 32757. It might be that this exercise expects a min and max, though it is not specified.
There is nothing wrong in the second part.
I have made changes to the first part but still same problem.
By the way, I got through the exercise, the exercise wanted only one character to be printed after rand().
echo rand(0, 8);
$name = "Sudeep Sagar";
$num = rand(0, strlen($name)-1);
echo substr($name, $num, 1);
Your first code that you set should work. He's good!