+ 6
How to input the number in php?
I tried to input the number through readline() function but it doesn't work.
16 Answers
+ 7
<html>
<body>
<form action="site.php" method="get">
Name: <input type="text" name="username"> <br>
Age: <input type="number" name="age"> <input type="submit" name="submit" value="send">
</form>
<br>
<?php
if(isset($_GET["submit"])){
echo "Your name is " . $_GET["username"] . ",<br>";
echo "You are " . $_GET["age"] . ".";
}
?>
</body>
</html>
+ 7
JaScript hmm, that's really sad btw thank you bro for helping and give the information.
+ 7
˹ᴅᴇᴠᴇʟᴏᴘᴇʀ ᴛᴧɴᴊᴇᴅ˼ I already tried don't work in sololearn
+ 6
as I remember sololearn doesn't have a console for php so
php -a
for interactive tools won't work
but you can try
echo '<script>document.write(prompt())</script>';
a little hybrid mixture
+ 6
Snehil bro if I want to take input number like this:-
$a = readline ()
Then how can I input like this?
+ 6
Snehil hmm, it means we can't take input in easy way, btw thank you for the information.
+ 6
Unfortunatelly SL do not support php.
+ 6
You are welcome Sakshi
By the way in php console you could input a number with:
(int)readline(“please enter a number“)
+ 6
Волгина Варвара I tried don't work in sololearn
+ 5
JaScript I tried it bro, not works, I think I am wrong 🤔
https://code.sololearn.com/wru007rIHFw4/?ref=app
https://code.sololearn.com/W6mcZpC6X5Ur/?ref=app
+ 5
JaScript Yah I know bro, thank you 😊
+ 3
that works in console(CLI) not on web page
+ 3
https://code.sololearn.com/wmzkuHp2LaTR/?ref=app
I tried accessing CLI input and I was successful in that but the machine didn't allowed user to give input u can see the code
+ 3
Using the readline function: If you want to prompt the user to enter a number from the command line, you can use the readline function, like this:
$number = readline("Enter a number: ");
+ 2
$number = readline();
0
readline() will work when you running php in cmd/termux
On Web/localhost uses make request
$num = $_REQUEST['num']
then yourfilename.php?num=YourNumber?