Reputation: 1264
I hope this question makes sense - it might be that I don't fully understand what is going on.. but after a considerable amount of googling to no avail here goes:
What I'm trying to do is execute a PHP file on the command line using php filename.php
and get the output as HTML - so it could be displayed as a webpage. Currently the command line is just returning raw text output with no HTML tags. Currently the only line of code in PHP file is: <?php phpinfo() ?>
Is this possible? If not, how does MAMP etc execute that file to produce a HTML output?
Thanks!
Upvotes: 4
Views: 5757
Reputation: 1601
Where phpinfo.php contains:
<?php phpinfo();
From the console, to generate an HTML file of the phpinfo() output:
php-cgi phpinfo.php > phpinfo.html
The important thing is to use php-cgi instead of php if you want the output to contain HTML when executed from the console.
Upvotes: 1
Reputation: 2057
If you use php-cgi instead of php from the CLI your program will run as if it were running on a webserver. It won't have access to anything in $_SERVER, $_POST, $_GET etc but it will cause phpinfo() to produce HTML instead of plain text.
Upvotes: 7
Reputation: 3108
phpinfo() function is smart enough to identify where request is coming from if it is coming from CLI then it doesn't return the html but when request is coming from apache it merge it with html and sends the output.
there is a example listed here for converting cli raw output of phpinfo() to html but I have not tried it.
Upvotes: 2
Reputation: 59987
HTML is text (ASCII for example) output that contains sequence of characters that have special meaning.
Do something like this
php filename.php > webpage.html
Then view webpage.html
with your browser.
As to the function phpinfo()
I am not quite sure what environment/global variables are required to produce output.
Upvotes: 3
Reputation: 35139
HTML is just text. There's nothing special about it.
<?php
echo '<p>this is html, you'll want the header, body tags, and content.';
?>
Upvotes: 1
Reputation: 4399
phpinfo()
does not output HTML if it's executed from the command line. HTML will however be returned as text when executed in the command line.
Upvotes: 1
Reputation: 75619
You have to produce HTML, not MAMP, LAMP or anyone else. You run the program and the program produces its output. So if you want to see HTML, just spit out HTML.
Upvotes: 0