PHP Functions, Part 1


#1


Oops, try again. Please follow the instructions on the Full Preview page to test your code.


Replace this line with your code. 
the code generates a random letter when i click on view in full screen, but when i click submit, the page times out.

<?php
    // Use your knowledge of strlen(), substr(), and rand() to
    // print a random character from your name to the screen.
        $name = 'brandy';
        echo substr($name, rand(0, strlen($name)-1), 1);
        
    ?>


#2

Hello @bvines107,
in the flood of too many threads someone didn't see yours maybe :stuck_out_tongue:

Well, it says you should print a random char from your name. echo does (afaik) the same, but well - print is demanded this time.

And I would set the random position in a seperated variable

Try this:

<?php
    // Use your knowledge of strlen(), substr(), and rand() to
    // print a random character from your name to the screen.
    $name = 'brandy';
    $pos = rand(0, strlen($name) - 1);
    print substr($name, $pos, $pos + 1);
?>

Hope this will help you :slight_smile:


#3

the code i originally had above worked, i just had to refresh the page.
thank you