Skip to content
Home » How to Get Input Value From User in PHP?

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:

FAQs: Get user input in PHP

  • How we can take input from users in PHP?

    To take input from users in PHP without using HTML form, you can use PHP inbuilt readline() function.

    Was this article helpful?
    YesNo
  • How can I take input from HTML to PHP?

    Using GET and POST method and input type’s name attribute user can take input from HTML form.

    Was this article helpful?
    YesNo
  • How can I get input field value in PHP without submit?

    Using JavaScript we can get the element. Or you can also use jquery to access the value. by using id = "something" and retrieve it using $('#something').val();

    Was this article helpful?
    YesNo
  • Happy Coding..!

    Was this article helpful?
    YesNo

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

    1. Pingback: How to Check Process Running in Windows - PHPCODER.TECH

    2. Pingback: How to Execute PHP File From Command Line - PHPCODER.TECH

    Leave a Reply

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