Reputation: 3657
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?
Upvotes: 0
Views: 12518
Reputation:
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
Upvotes: 0
Reputation: 6592
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.
Upvotes: 0
Reputation: 76408
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
Upvotes: 2
Reputation: 1575
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.
Upvotes: 0