is there a way to take an html string and render it as a web browser would, from the command line?

L

lkrubner

I'd like to write a PHP script to be used from the command line on a
Unix machine. I'd like for the script to put together a string, turn it
into a web page, print it, then return control the command line.

Obviously it is quite easy to make a string that is valid HTML and send
it to the printer. The tough part is making look like a web page. In
particular, image tags should print out as images, not image tags.

Does anyone have an idea about how this is done?

Many thanks in advance.
 
J

J. Gleixner

I'd like to write a PHP script to be used from the command line on a
Unix machine. I'd like for the script to put together a string, turn it
into a web page, print it, then return control the command line.

Obviously it is quite easy to make a string that is valid HTML and send
it to the printer. The tough part is making look like a web page. In
particular, image tags should print out as images, not image tags.

Does anyone have an idea about how this is done?

Yes, lots of people have an idea. You'll find your PHP answer in a PHP
newsgroup, not one about perl.
 
I

Ian Wilson

I'd like to write a PHP script to be used from the command line on a
Unix machine. I'd like for the script to put together a string, turn it
into a web page, print it, then return control the command line.

Obviously it is quite easy to make a string that is valid HTML and send
it to the printer. The tough part is making look like a web page. In
particular, image tags should print out as images, not image tags.

Does anyone have an idea about how this is done?

I wouldn't use PHP, I'd use Perl to produce a normal HTML file and
associated image files (.png .jpg or whatever). Then I'd aim to have the
script invoke mozilla to do the rendering of the images in the page and
printing of the rendered page.
 
L

lkrubner

I'd like to write a PHP script to be used from the command line
Yes, lots of people have an idea. You'll find your PHP answer in
a PHP
newsgroup, not one about perl.

Awful sorry, I meant to write "PHP or Perl script". I can write it in
either language, obviously. I'm wondering how to do it and which
language would be easier.
 
L

lkrubner

I wouldn't use PHP, I'd use Perl

I'm sorry I only mentioned PHP. I meant to ask "PHP or Perl".


to produce a normal HTML file and
associated image files (.png .jpg or whatever). Then I'd
aim to have the
script invoke mozilla to do the rendering of the images
in the page and
printing of the rendered page.

Great. That is a good tip. Where can I go to find information about how
to invoke mozilla to do this?

Any direction you can give me toward good information sources is much
welcome.

--lk
 
L

lkrubner

I wouldn't use PHP, I'd use Perl

I'm sorry I only mentioned PHP. I meant to ask "PHP or Perl".


to produce a normal HTML file and
associated image files (.png .jpg or whatever). Then I'd
aim to have the
script invoke mozilla to do the rendering of the images
in the page and
printing of the rendered page.

Great. That is a good tip. Where can I go to find information about how
to invoke mozilla to do this?

Any direction you can give me toward good information sources is much
welcome.

--lk
 
J

J. Gleixner

You don't turn something "into a web page", you add HTML entities
which help a browser display the text/information.

The answer to the statement in your subject is "no". It's rendered in
a browser or via some software/interface. You could use something
like lynx, to render it, but it'll only render text.
Awful sorry, I meant to write "PHP or Perl script". I can write it in
either language, obviously. I'm wondering how to do it and which
language would be easier.

Obviously it's not that obvious.

You'd be the one to determine which is easier and what your platform
is enabled to handle, PHP and/or CGI. It sounds like you're wanting to
do something like a CGI, look around the web for "cgi tutorial". If
your server already has PHP, then look for "php tutorial".

Your question is so general that you should start with one of the many
tutorials, and go from there.

Since this is a perl newsgroup, if you want to run a perl script
that produces HTML, you could take a look at using the CGI module:

http://search.cpan.org/~lds/CGI.pm-3.11/CGI.pm

or just hard code all of your HTML in your "string", then print the
"string".

A trivial script, using CGI to output the HTML, would be to
create a file, say 'create_it.pl':

#!/usr/bin/perl
use CGI qw:)standard);
print
start_html,
h1('my page'),
end_html;

Run it and redirect it to a file:

perl ./create_it.pl > test.html

Then use the browser to view the test.html file.

Search the Internet for HTML tutorials, if needed.
 
L

lkrubner

You don't turn something "into a web page", you add HTML
entities
which help a browser display the text/information.
The answer to the statement in your subject is "no". It's
rendered in
a browser or via some software/interface. You could use
something
like lynx, to render it, but it'll only render text.

Okay. And someone else mentioned using the rendering image of Mozilla.
Do you think I can also invoke either lynx or mozilla to send the web
page to the servers printer?


You'd be the one to determine which is easier and what your
platform
is enabled to handle, PHP and/or CGI. It sounds like you're
wanting to
do something like a CGI, look around the web for "cgi tutorial". If
your server already has PHP, then look for "php tutorial".

I don't think I want to do a CGI. I want a shell script that can be
invoked from the command line. It'll actually be invoked from another
shell script. The idea is to query our database server and get back
images of motorcycles, plus information about those motorcycles, then
send that report to the printer, and then return control to the command
line. It's on a server that is running HP Unix. Both Perl and PHP are
installed.

If you can point me towards information about invoking web browsers
such as lynx or mozilla, I'd appreciate it.

Thanks.
 
A

A. Sinan Unur

(e-mail address removed) wrote in @f14g2000cwb.googlegroups.com:
Okay. And someone else mentioned using the rendering image of Mozilla.
Do you think I can also invoke either lynx or mozilla to send the web
page to the servers printer?

What does that have to do with Perl?

Read the docs for lynx or Mozilla. Ask on the appropriate groups.

Sinan
 
R

RedGrittyBrick

I'm sorry I only mentioned PHP. I meant to ask "PHP or Perl".






Great. That is a good tip. Where can I go to find information about how
to invoke mozilla to do this?

Any direction you can give me toward good information sources is much
welcome.

This is off-topic for comp.lang.perl.misc but Googling for "mozilla
command line options" leads to a URL that tells you how to do it.

Note the --remote option and its example. Study the menu shortcuts in
Mozilla.
 
J

Joe Smith

PHP scripts run inside a web server. They don't run from the command
line since it does not provide the proper environment.

A web page is a string. Since you've got a string, you already
have a web page. You're really asking for is rendering HTML.

Since JavaScript exists in many HTML documents, you'll want to
use a real browser and not a feature-poor re-implementation in perl.

1) Write HTML string to a file.
2) Use the command-line interface to Netscape/Mozilla/Firefox to
get it to open the local file.
3) Use the command-line interface to tell the browser to send
the document to a printer, then exit.
4) Delete the temporary file.

-Joe
 
C

chris-usenet

Joe Smith said:
PHP scripts run inside a web server. They don't run from the command
line since it does not provide the proper environment.

Those statements are as untrue for PHP as they are for Perl.
Chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top