Monday, April 30, 2012

How can I capture user input from the cmd line using PHP?

Copy and paste the following command into your shell to create a new file in your current directory:
vim example.php
Copy and paste the following text into your new example.php file:
<?php
$name = trim(shell_exec("read -p 'Enter your name: ' name\necho \$name"));
echo "Hello $name this is PHP speaking\n";
exit;
Save the example.php file.

Next, experience your new PHP program (example.php) capture your user input from the cmd line by copying and pasting the following command into your shell:
php example.php
It will prompt you with the following:
Enter your name: 
You will type your name and then hit enter as shown here:
Enter your name: John
After you hit enter you'll see the PHP program we wrote print out the following text:
Hello John this is PHP speaking
Looking for a cloud-based catalog and CRM platform? Checkout http://rocware.com/

28 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. Thanks a lot for sharing us about this update. Hope you will not get tired on making posts as informative as this. 

    Java training in Chennai

    Java training in Bangalore

    ReplyDelete
  4. Thanks For sharing the Information The Information Shared Is Very valuable please Keep Updating Us The InFormation Shared Is Very Valuable Python Online Training Hadoop Online Training <a href="https://nareshit.com/data-science-online-training/>DataScience Online Training</a>

    ReplyDelete
  5. It’s an amazing piece of writing for all the internet users;
    they will take benefit from it I am sure.
    Insufficient Storage

    ReplyDelete
  6. With an engaged mind and satisfied mindset, I just loved your content. Pure content and relevance with excellent presentation. Your blog will soon have number of visitors if you keep sharing more. Hey, I have been using QuickBooks for so long now. In case you need QuickBooks assistance, you can contact the best customer care executives at QuickBooks Support Phone Number +1 833-228-2822.

    Read More: QuickBooks Error 3371

    ReplyDelete
  7. Thank you for your post. This is excellent information. It is amazing and wonderful to visit your site.hadoop training institutes in bangalore

    ReplyDelete
  8. Your topic is very nice and helpful to us … Thank you for the information you wrote.

    Upgrade your career Learn AWS Training from industry experts get Complete hands-on Training, Interview preparation, and Job Assistance at Bangalore Training Academy Located in BTM Layout.

    ReplyDelete
  9. Very interesting, good job and thanks for sharing such a good blog.

    Upgrade your career Learn SharePoint Developer Training in Bangalore from industry experts get Complete hands-on Training, Interview preparation, and Job Assistance at Softgen Infotech.

    ReplyDelete
  10. This post is really nice and informative. The explanation given is really comprehensive and informative . Thanks for sharing such a great information..Its really nice and informative . Hope more artcles from you. I want to share about the best java videos with free bundle videos provided and java training .

    ReplyDelete
  11. Excellent post for the people who really need information for this technology.data science courses

    ReplyDelete
  12. Thanks for the Valuable information.Really useful information. Thank you so much for sharing. It will help everyone.

    SASVBA Provides the Data analytics course in Delhi with the Latest Development Environment and Structures. We keep Our Programs Up to Date with the Latest modern trends. SASVBA Is One of the best education Data Analytics courses in Delhi Which Helps Learners Crack Interviews in Tech Giants.
    FOR MORE INFO:

    ReplyDelete
  13. Thats great post !! I like ur every post they always give me some new knowledge.

    VidMate | VidMate for PC |
    VidMate 2014

    ReplyDelete
  14. This comment has been removed by the author.

    ReplyDelete
  15. Really impressed! Everything is very open and very clear clarification of issues. It contains true facts. Your website is very valuable. Thanks for sharing.
    data analytics course in hyderabad

    ReplyDelete
  16. Appreciation for sharing this bend towards. I in truth other than your weblog uncover no think about packs. you have in truth shared an illuminating and drawing in weblog dissipate following individuals.. Free Quick Heal Product Key

    ReplyDelete
  17. Ive been attempting to find a few respectable stuff concerning the challenge and dock't had any good fortune going on till this narrowing, You simply got a subsidiary biggest lover!.. Good Bye Wishes

    ReplyDelete
  18. StudioLine Photo Classic is compatible with both Windows and Mac OS X.
    https://thepcsoft.com/studioline-photo-classic/

    ReplyDelete
  19. Very informative Blog by you for the people who are new to this industry. Your detailed blog solves all the queries with good explanation. Keep up the good work. Thanks for sharing! We have a website too. Feel free to visit anytime.

    two piece dress western

    knee length western dress

    ReplyDelete
  20. Very informative Blog by you for the people who are new to this industry. Your detailed blog solves all the queries with good explanation. Keep up the good work. Thanks for sharing! We have a website too. Feel free to visit anytime.

    Car Transport service in Mumbai

    bike transport service in Mumbai

    ReplyDelete

About Me

My photo
I code. I figured I should start a blog that keeps track of the many questions and answers that are asked and answered along the way. The name of my blog is "One Q, One A". The name describes the format. When searching for an answer to a problem, I typically have to visit more than one site to get enough information to solve the issue at hand. I always end up on stackoverflow.com, quora.com, random blogs, etc before the answer is obtained. In my blog, each post will consist of one question and one answer. All the noise encountered along the way will be omitted.