In this tutorial, we Get Input Value From the User without using any HTML form and the GET and POST method.
Here are the steps which we follow to achieve the task,
- Creating a PHP script with
- Save it to your related path.
- Run using CMD in windows OS and Terminal in Linux OS.
Returns the string from the user and ask for input from the user.
In This Article
Live Demo to Get Input Value From User in PHP
Creating a PHP script with readline function
To achieve the task we have to use readline() function which helps to get the input from the user.
// Input section
// $a = 20
$a = (int)readline('Enter an integer: ');
// $b = 20.12
$b = (float)readline('Enter a floating'
. ' point number: ');
// Entered integer is 20 and
// entered float is 20.12
echo "Entered integer is " . $a
. " and entered float is " . $b;
Enter an integer: 20
Enter a floating point number: 20.5
Entered integer is 20 and entered float is 20.5
How to Run The PHP Code
- Save it to your server path (if local server C:\xampp\htdocs\test.php)
- Open your command line and go to the same path.
- Run using PHP command (
In this article, we check how we get user input in PHP without using HTML form. We use CMD or command line to run the PHP code with the prompt for the user to input the data.
We use readline() PHP inbuilt function to do the complete task.
You can know more about readline function here https://www.php.net/manual/en/function.readline.php
- isset vs empty vs is_null in PHP With Example
- Get PHP Date Time Difference in Days, Hours, Minutes, and Seconds
- PHP Timestamp to Date Readable Format With Example
FAQs: Get user input in PHP
To take input from users in PHP without using HTML form, you can use PHP inbuilt readline() function.
Using GET and POST method and input type’s name attribute user can take input from HTML form.
id = "something" and retrieve it using