Has PHP own print command?

Discussion in 'PHP' started by admins, Jan 10, 2008.

  1. #1
    We can print output from explorer print option. But has PHP built function that used to print? Specially, in a custom way, like, any part of it.
     
    admins, Jan 10, 2008 IP
  2. LittleJonSupportSite

    LittleJonSupportSite Peon

    Messages:
    386
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    0
    #2
    No this can only be done on the client side.

    PHP is a server side language.

    JavaScript is what you need.
     
    LittleJonSupportSite, Jan 10, 2008 IP
  3. wmtips

    wmtips Well-Known Member

    Messages:
    601
    Likes Received:
    70
    Best Answers:
    1
    Trophy Points:
    150
    #3
    PHP is a server side language and executes on the server, not on client. Do you want to amaze your datacenter workers?
    I think there is no printer there :D
     
    wmtips, Jan 10, 2008 IP
  4. admins

    admins Peon

    Messages:
    74
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thanks LittleJOn, It shows it is your 50th post. Congrates!! for fifty.
    If I use Java Script along with PHP, is print possible?
     
    admins, Jan 10, 2008 IP
  5. Kieran.in

    Kieran.in Peon

    Messages:
    22
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Depends how you want to do it admins

    If you wish to print on the machine running PHP, then yes you can.
     
    Kieran.in, Jan 10, 2008 IP
  6. Kieran.in

    Kieran.in Peon

    Messages:
    22
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Er, well you would normally use PHP to generate a "clean" and printer-friendly page from your database (if your using one).


    You would then just need to do this:

    <a href="javascript:window.print();">Print</a>


    Sorry about double post, hit wrong button -.-
     
    Kieran.in, Jan 10, 2008 IP
  7. nicangeli

    nicangeli Peon

    Messages:
    828
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Yes, the above is correct. You can use google to find more detaild explanations but the following should work, (not tested)

    
    <a href="JavaScript:window.print();">Print this page</a>
    
    Code (markup):
    EDIT: Sorry, that above must have been posted when i was typing.
     
    nicangeli, Jan 10, 2008 IP
  8. wmtips

    wmtips Well-Known Member

    Messages:
    601
    Likes Received:
    70
    Best Answers:
    1
    Trophy Points:
    150
    #8
    I would not recommend to make duplicate content for printer. Instead of it use CSS for printer-friendly page tuning. Just include another CSS and hide unwanted blocks:

    <link rel="stylesheet" type="text/css" href="print.css" media="print" />
    HTML:
     
    wmtips, Jan 10, 2008 IP
  9. admins

    admins Peon

    Messages:
    74
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Thanks for your code.
    Say, I have many data in database, And say from different country. And I want to print them countrywise in seperate page. What should be done?
     
    admins, Jan 10, 2008 IP
  10. Kieran.in

    Kieran.in Peon

    Messages:
    22
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10

    Thats a good method to use, but when your site has a lot of content, and maybe a variation of templates it may fail.

    Duplicate content is fine, such as the lofi version for some forums.

    It's easier too.
     
    Kieran.in, Jan 10, 2008 IP
  11. wmtips

    wmtips Well-Known Member

    Messages:
    601
    Likes Received:
    70
    Best Answers:
    1
    Trophy Points:
    150
    #11
    You choose. But having duplicate content can affect your SE rankings. For example Google can just prefer "printer-friendly" page and skip real page with ads etc. :)
     
    wmtips, Jan 10, 2008 IP