How to Get Input Value From User in PHP?

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,

  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 ask 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 the 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 PHP command (php filename.php)
Run PHP on console
Run PHP on 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
    My name is Bikash Kr. Panda. I own and operate PHPCODER.TECH, my native place in Odisha. I am a Web Programmer by profession and working on more than 50 projects to date. My passion is working on the web-based project using PHP and relate to all CMS and frameworks which is based on PHP.
    Posts created 175

    One thought on “How to Get Input Value From User in PHP?

    Leave a Reply

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

    Related Posts

    Begin typing your search term above and press enter to search. Press ESC to cancel.

    Back To Top
    mariobet - supertotobet - escort -

    takip7.com

    - milanobet giriş - gizabet giriş -
    perabet giriş
    - betkanyon giriş -

    jojobet giriş

    We are now accepting guest posting and creation of back-links.
    This is default text for notification bar