PHP - Functions, Part I : 5.Math Functions II


Error ; Your printed output from rand() should be an integer.

echo rand(0,10);
echo "

$name = "Tempo";
$ran= rand( 0,strlen($name)-1);
$sub=substr("Tempo", $ran);
print $sub;
// Use your knowledge of strlen(), substr(), and rand() to
// print a random character from your name to the screen.


substr needs three arguments and you're giving only two!
$sub=substr("Tempo", $ran);


$name= "bharath";
$length= strlen("bharath");
$random= rand (substr($length,0,3),substr($length,3,-1));
print $random;


The error was about integer and not this string, it is working with two arguments. I solved it the issue I had. Thanks.


Thanks and yeah I just noticed my mistake! :thumbsup:


$len = strlen($name);
$ran = rand($len - 1, $len);
$sth = substr($name, $ran);
print $sth;


still it is incorrect...


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.