please tell me.

<?php error_reporting(-1); $a=2; $x=4+$a; echo "ответ будет $x "; ?> 

I have such an elementary code, but I want the user to enter $a from the keyboard.

How to call the operator and the line in which to enter $a ?

thank you in advance

    3 answers 3

    If you are going to run the script from the console, readline () - what you need:

     <?php $a=readline("a="); echo "your input is $a\n"; ?> 

      It is necessary to make for example an html-form:

      The page with the form (for example form.php ):

       <form action="script.php"> <input name="param_name" /> <button type="submit">Send</button> </form> 

      And the handler:

      For example ( script.php as indicated in the <form> tag with the action attribute):

       <?php $var = $_GET['param_name']; //индекс зависит от имени поля echo 'recived: ' . $var; ?> 

        Your task is solved using forms. For example, I will give a simple form:

        Index.php

         <html> <body> <form action="welcome.php" method="get"> Имя: <input type="text" name="firstName"><br> Фамилия: <input type="text" name="lastName"><br> <input type="submit"> </form> </body> </html> 

        welcome.php

         <html> <body> Привет <?php echo $_GET["firstName"]; ?> <?php echo $_GET["lastName"]; ?> </body> </html> 

        Successful coding ...