Fatal error: Call to undefined function stren() on line 12


#1



<?php
// Use rand() to print a random number to the screen
print rand(1,6);
?>



<?php
// Use your knowledge of strlen(), substr(), and rand() to
// print a random character from your name to the screen.
print rand(stren("saptha"),substr("sapthagiri",0,9));
?>



#2

@saptha_clans

Look here

You must call to the function strlen not stren


#3

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.how to do this sir i got no idea please teach me


#4

@saptha_clans
First of all, let's review what those function does.

strlen:

Strlen is a function which only parameter accepted is a string. It will return the length of the string input as a parameter. Here's an example of how it works:

echo strlen("wow"); // It returns 3 since the length of "wow" is three

More info

rand

Rand is a function which have two parameters accepted. Both are integer value. This function will return a random number between the min and max input. Here's an example of how to use:

echo rand(3, 20); // return a random number between 3 and 20

More info

substr

Substr is a function which have two parameter accepted. The first one is a string, the second is the start of where you want to index the position where you want to cut the string. The last one is the length which is optional if the value of start parameter is less than 0 is considered like where you want to cut your string. Here's how it work:

echo substr("string", 1, 3); // return "tri" because it's indexed

More info

In the instruction, it tells you to play around with these strings. Here's what you started:

See, rand function only parameter accepted is an integer and your substr will print a part of a string. Plus, it asks you to print a random character inside of your name and rand function will print a number. So you need to change. I can't print out the code for you otherwise that will be cheating (Community Guidelines) but I can give you examples and explanation of how to do it.

You can first of all use the substr function which will print a string (that's what we want! + your name surely doesn't contain any number in it!). In the first parameter, you will input your name since it only accepts strings. In second and third parameter, use rand and strlen function to define the start and length parameter. Remember that start parameter should not have a negative value otherwise it will return false!


#5

Thank you very much sir :slightly_smiling: