How to take user input in php, how do we take it in c / C ++?

How to accept user input in php, as we take it in c / C ++, I write a program in codechef and try to write it in php, but I can’t get user input, please help. !!

+4
source share
2 answers

Do you mean php cli?

<?php
$temp = fopen("php://stdin","r");
$line = fgets($temp);
echo $line;
?>

Take a look at http://php.net/manual/en/features.commandline.php

+11
source

You must use an HTML form to enter user input. For example:

<?php
if(isset($_POST['submit'])) /* i.e. the PHP code is executed only when someone presses Submit button in the below given HTML Form */
{
$var = $_POST['any_name'];   // Here $var is the input taken from user.
}
?>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<input type="text" name="any_name">
<input type="submit" name="submit">
</form>
-1
source

All Articles