How to input the number in php? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 6

How to input the number in php?

I tried to input the number through readline() function but it doesn't work.

8th Apr 2023, 3:45 PM
Sakshi [Less Active]
Sakshi [Less Active] - avatar
16 Respostas
+ 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>
8th Apr 2023, 5:39 PM
JaScript
JaScript - avatar
+ 7
JaScript hmm, that's really sad btw thank you bro for helping and give the information.
8th Apr 2023, 6:17 PM
Sakshi [Less Active]
Sakshi [Less Active] - avatar
10th Apr 2023, 8:09 AM
Sakshi [Less Active]
Sakshi [Less Active] - avatar
+ 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
8th Apr 2023, 4:20 PM
I am offline
I am offline - avatar
+ 6
Snehil bro if I want to take input number like this:- $a = readline () Then how can I input like this?
8th Apr 2023, 4:31 PM
Sakshi [Less Active]
Sakshi [Less Active] - avatar
+ 6
Snehil hmm, it means we can't take input in easy way, btw thank you for the information.
8th Apr 2023, 5:23 PM
Sakshi [Less Active]
Sakshi [Less Active] - avatar
+ 6
Unfortunatelly SL do not support php.
8th Apr 2023, 6:02 PM
JaScript
JaScript - avatar
+ 6
You are welcome Sakshi By the way in php console you could input a number with: (int)readline(ā€œplease enter a numberā€œ)
8th Apr 2023, 7:12 PM
JaScript
JaScript - avatar
10th Apr 2023, 8:10 AM
Sakshi [Less Active]
Sakshi [Less Active] - avatar
8th Apr 2023, 5:57 PM
Sakshi [Less Active]
Sakshi [Less Active] - avatar
+ 5
JaScript Yah I know bro, thank you šŸ˜Š
8th Apr 2023, 7:15 PM
Sakshi [Less Active]
Sakshi [Less Active] - avatar
+ 3
that works in console(CLI) not on web page
8th Apr 2023, 4:34 PM
I am offline
I am offline - avatar
+ 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
8th Apr 2023, 4:47 PM
I am offline
I am offline - avatar
+ 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: ");
9th Apr 2023, 10:02 PM
Ė¹į“…į“‡į“ į“‡ŹŸį“į“˜į“‡Ź€ į“›į“§É“į“Šį“‡į“…Ė¼
Ė¹į“…į“‡į“ į“‡ŹŸį“į“˜į“‡Ź€ į“›į“§É“į“Šį“‡į“…Ė¼ - avatar
+ 2
$number = readline();
10th Apr 2023, 8:09 AM
Š’Š¾Š»Š³ŠøŠ½Š° Š’Š°Ń€Š²Š°Ń€Š°
Š’Š¾Š»Š³ŠøŠ½Š° Š’Š°Ń€Š²Š°Ń€Š° - avatar
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?
25th Oct 2023, 4:33 AM
MrSatyamSoni
MrSatyamSoni - avatar