Jul 25, 2008

Question: Anybody Know How To Make Print Command?

Free Web Hosting, No Ads > CONTRIBUTE > Computers > Programming Languages > PHP Programming
Pages: 1, 2, 3

free web hosting

Question: Anybody Know How To Make Print Command?

.hack//GU
I want my site (with PHP) to enable PRINT command. The usual print, with printer as output I mean. So, how can I do it? I've seen my college site use ASP and they can give me a PRINT xommand box, when I click it the printer will print the page.

Reply

Spectre
Take a look at the Printer Functions reference. These apparently only work on certain versions of Windows, and require additional PECL extensions (I have not tested any of these functions, and therefore cannot really comment).

There's an example on the print() function listing for sending output to a printer (note that the print() function simply displays output), apparently taken from Tufat.com. This example is also on Windows, and at a glance, appears to utilize Acrobat Reader, Microsoft Word or Microsoft Excel to do the actual printing.

Reply

elrohir
isnt is easier to have it in javascript? (you can always escape it into a PHP echo if you really insist)..

HTML
<a href="java script:window.print()">Print</a>



nothing wrong with simple stuff tongue.gif

Reply

dazappa
Yes, doing that in javascript would be a lot easier considering you can add javascript above or below your
<?php tag. That's the great thing about php. You could also make it print with a button, not just a link.

Reply

Spectre
The example in the print() command reference calls a COM event to trigger the printing, which is similar to how JavaScript operates - however, PHP is server-side, JavaScript is not. I don't think .hack//GU simply wants to print the current page rendered by the browser.

Reply

Justin S.
You push ctrl p or for apple the little wierd sign with the apple next to it then p.

Reply

elrohir
QUOTE(Spectre @ May 20 2006, 02:58 AM) *

The example in the print() command reference calls a COM event to trigger the printing, which is similar to how JavaScript operates - however, PHP is server-side, JavaScript is not. I don't think .hack//GU simply wants to print the current page rendered by the browser.


That is why I mentioned escaping into PHP... as in

CODE

<?php

echo "<a href=\"java script:window.print()\">Print</a>;

?>


or what ever way of returning you happen to want to use...

Reply

Spectre
Ok, now let's review what that does: causes the script to output a simple JavaScript statement in plaintext which the visitor's browser will then interpret as it will, which is exactly the same as adding it in the HTML. It isn't going to execute anything at the server's end, and solves little.

I think one (or more?) of us is misunderstanding .hack//GU's problem here. I'm assuming he wants to send output to the printer at the server, not the client. JavaScript has no control over the server whatsoever. All the window.print() function will do is cause the browser the visitor is using (assuming it supports JavaScript) to print the current webpage, with nothing happening at the server's end whatsoever. I don't know why you would want to use PHP to print anything in the first place, but as .hack//GU posted it in the PHP programming forum, I'm assuming that is what he is after.

Reply

elrohir
QUOTE(.hack//GU @ May 19 2006, 11:50 AM) *

The usual print, with printer as output I mean.


I take that as wanting the user to be able to print - with a printer - the page he is viewing. Perhaps .hack//GU would like to correct me?

The reason I would do it in PHP is that then you can have it inside a logic syntax, which is rather handy... but then I am probably just too noobish to understand your advanced methods of thinking, arn't I?

Also about escaping in PHP - dont use heredoc syntax, even if it is easier...

Reply

Spectre
With all due respect - and I do mean that - do you actually know what you're talking about?

This:
CODE
<?php
echo '<a href="java script:window.print()">Print</a>';
?>


Will produce the exact same result as simply placing:
CODE
<a href="java script:window.print()">Print</a>


Somewhere in the HTML. All your code is doing is outputting the text. It doesn't use PHP to print at all. Just JavaScript. No PHP. JavaScript only. PHP is not being used. JavaScript is. PHP does nothing here. JavaScript does everything. Outputing code as text does not cause it to be executed in any form; you cannot combine JavaScript and PHP to operate together at a server-level as JavaScript is client-side, and only operates from within the user's browser (if it supports JavaScript, of course).

Just to re-iterate: what you are suggesting does not use PHP at all.

[edit] For some reason (security?), the IPB code parser is insisting that 'javascript' become 'java script'. There should not be a space in the link.

 

 

 


Reply

Latest Entries

elrohir
wee then we are all happy then, and since .hack//GU is not really taking part, I guess we solved his problem somewhere along the line. If so, why the hell are we discussing this?

Reply

Spectre
I seem to remember suggesting how to physically print with PHP in the first post I made in this thread - the only post which, might I point out, actually addressed the problem exactly as .hack//GU described it.

I'm not saying there is never a benefit to dynamically displaying JavaScript code. If you read my previous post, I said 'In this case, there is absolutely no benefit...'. Yet you continue to insist there is.

I'm glad you find my refusal to agree with pointlessly wasting time and inability to build an empty argument on that 'hilarious'. I share a similar view of your inability to grasp logic and reason.

Reply

elrohir
lol, doesnt have to be double quotes, if you insist - but I dont think that one line of code will greatly influence parsing time unless you have a freaking slow server and a 5 bps server.

But say you have this huge page of code, with a switch on $page_id, and heredoc constructs for page output. Obviously, if you put the JS as plain html, it will appear on every single page which the switch concerns - This may not be very desirable, so you would then put it in PHP. Please, try to look from a different point of view. I am not saying that the result is any different from just plain html, or that PHP would be the one doing the printing. All I am saying - and ask Moldboy, who seems to understand my point - is that there is a benefit in putting it inside PHP. Even though PHP would not do the actual printing. And even though it could be done with just plain html/JS...

I agree that this is getting silly, but I still find it hilarious that you have not grasped the point yet.

But is .hack//GU even following this post? In the time we have spent arguing, he has most likely finished his site and started selling like heill... I really would like to finish my own, you know.... Moldboy, you obviously did not read the whole thread properly. But Spectre, you did not answer my question: Do you have a better PHP way of doing it?

Reply

Spectre
*Sigh. Here we go again. Despite saying my previous post would be my last in this topic..

moldboy, please don't argue just for the sake of arguing. This is getting ridiculous and childish. Outputting JavaScript via PHP involves PHP doing nothing outside of sending the data as output; it has absolutely no influence over nor is it all influenced by how the outputted JavaScript operates. Obviously, having PHP send output is using PHP; I was referring to the fact that it is not using PHP to instigate whatever operation the JavaScript will then execute. In this case, there is absolutely no benefit in having PHP send JavaScript as output over simply having it contained staticly within a file - quite the opposite in fact, it will result in further processing power being required in order to have the PHP output a non-dynamic piece of plaintext, especially if you use doublequotes as elrohir suggested. Illogical, pointless things frustrate me no end.

Reply

moldboy
No offence, but you two are nuts, you're not even arguing and yet seem to think that you are. One says you can't print with PHP (atleast not for the client) And the other one say that PHP doesn't parse javascript code. Both very good points, and very true, however they don't confict.

Now
QUOTE
Echoing JavaScript with PHP does not use PHP at all

yes it does, if you do something with php it uses php when you write echo "some JS code"; it uses php, it just does.
QUOTE
I don't know why you would even suggest outputting JavaScript from PHP as a method that uses PHP, because it doesn't.
again if you use php to echo something then you DO use php, and why, perhapse elrohir felt it would be a good idea if .hack//GU knew you could enclose javascript inside the echo statement, and perhapse then bu knowing that .hack//GU would be able to have something which would only offer the print command to users who were signed in so
CODE

//set user logged in state
$loggedin = TRUE;

//determin output based on previous decision
if ($loggedin ==TRUE){
echo "the print command (I don't do JS)";
}
else {
echo "I'm sorry the print option is only available to registered users"
}


Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Pages: 1, 2, 3
Similar Topics

Keywords : command

  1. Looking For Command Line Based Sql Modification - Program Needed For SQL? (1)
  2. Php Post Command - (6)
    Hello I've been trying to connect two PHP scripts that have their separate logins. I want to
    create a PHP script that will use POST to send the username/password to another PHP script. I tried
    a lot of scripts but I can't seem to make it work. I have no idea how to find out what is wrong,
    has anybody any experience in this field?...
  3. Restarting Apache With Exec Command - apache restart (0)
    Hey im trying to restart apache throug a script and so far none of the php or perl scripts have
    worked and its just driving me mental restarting apache in the command window in windows is a
    simple as just typing apache -k restart and when i do that i works , but when i create a script to
    execute that command it fails, and when i try to create a script to execute a batch file that does
    exactly that it still fails, so im stranded will someone help me out please, coz this is really
    getting annoying....
  4. I Will Provide You With A Php Code That.. - ..enable you to use the 'echo' command. (0)
    **YOU DO NOT NEED ANY HTML TAGS FOR THIS SCRIPT**** Enter all values between the ' ' quotes
    //Define The Variables $cfg = array('sitename' => '', //Your Sites Name
    'footer' => '', //OPTIONAL, if you want your footer stored so that the
    echo command can display it. Ex: Copright ©2005 - Michael Fratello (the © is will turn
    into the copyright 'c') 'board_dir' => '', //Link to your
    message boards. (If you have any) ); ?> I recommend saving this file ...



Looking for make, print, command

Searching Video's for make, print, command
advertisement



Question: Anybody Know How To Make Print Command?



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE