Core PHP, How To

How to Get Input Value From User in PHP?

In this tutorial to Get Input Value From User in PHP, we will use the PHP readline function without using any HTML...

Written by Bikash · 1 min read >
How to Get Input Value From User in PHP

In this tutorial to Get Input Value From User in PHP, we will use the PHP readline function without using any HTML form and the GET and POST methods.

Here are the steps which we follow to achieve the task,

  1. Creating a PHP script with readline() function.
  2. Save it to your related path.
  3. Run using CMD in windows OS and Terminal in Linux OS.

readline() function: Returns the string from the user and asks for input from the user.

Live Demo to Get Input Value From User in PHP

How 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 input from the user.

Output:

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 the PHP command (php filename.php)
Run PHP on console
Run PHP on the console

Conclusion

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

Also Read:

[helpie_faq group_id=’6281’/]

Happy Coding..!

Was this article helpful?
YesNo
Written by Bikash
My name is Bikash Kr. Panda. I own and operate PHPCODER.TECH. I am a web Programmer by profession and working on more than 50 projects to date. Currently I am working on the web-based project and all the CMS and frameworks which are based on PHP. Profile

2 Replies to “How to Get Input Value From User in PHP?”

Leave a Reply

Your email address will not be published. Required fields are marked *