0

Right now I can run a PHP script from my Mac terminal like echoing some output, creating folders etc. That is just PHP which does not take any input parameters.

Is it possible to run a PHP script with an HTML part which consists of a form for entering a username which is again posted in the PHP part so that I can create a folder name with the entered username. I wanted to test it using Terminal, not a browser on the Mac.

I just tried running the script with html part and what I get in the terminal output is that the whole html part is just reflected as output in the terminal output including the tags. Is what I want possible?

4
  • You want to display a HTML form in a terminal window ? If you want to display HTML content, you will need a browser. Commented Apr 4, 2012 at 13:36
  • The simple answer is "no, it is not possible". Commented Apr 4, 2012 at 13:37
  • thanks for the comments guyz, I got my answer! Commented Apr 4, 2012 at 13:39
  • ...but there's ncurses bindings for PHP Commented Apr 4, 2012 at 14:32

4 Answers 4

2

PHP does take parameters from terminal, just execute your script ./myScript.php name and in your script $argv[1] will hold name. $argv[0] is the absolute path to the current script.

Though I'm not quite sure what your script is for, you might want to read up on the php-cli... it's far more elaborate than you seem to believe

Sign up to request clarification or add additional context in comments.

Comments

0

Apache is in charge of web request, you can't send a post to a php file without a web server. If you run the file in console all you will get is a bunch of HTML, but the console has no way to interpret the HTML, that's what the browser does, you can, however, make a PHP script to run in the console and request an username if that's what you need, that's the only way.

PHP has a built-in webserver with the latest version though, you might be able to use the browser just with PHP if you don't want a webserver like apache.

Comments

0

I don't think what you are asking is possible. The terminal doesn't 'know' what HTML is, it is really just a bunch of text strings. The reason HTML forms display in a browser is because the HTML is rendered.

PHP does support command line scripts, but instead of putting out HTML strings, you should just put out plain text strings. Terminal windows are no as interactive as a browser window so the best you could do is put out a question and wait for a text response. I've never done this with PHP and I don't know if it is possible. If you are familiar with PHP, you might find it relatively easy to migrate to Perl or Python, both of which would allow this style of interactive session.

Comments

0

To interpret HTML content, you will need a browser; a terminal window will only display the output in plain text format.

However, if you want to read input from a user in a terminal window, you might want to look at I/O streams: http://www.php.net/manual/en/wrappers.php.php

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.