PHP print function

print

(PHP 3, PHP 4, PHP 5)

print -- Output a stringDescriptionint print ( string arg )

Outputs arg. Returns 1,
always.

print() is not actually a real function (it is a
language construct) so you are not required to use parentheses
with its argument list.

Example 1. print() examples

PHP:
  1. print("Hello World");
  2.  
  3. print "print() also works without parentheses.";
  4.  
  5. print "This spans
  6. multiple lines. The newlines will be
  7. output as well";
  8.  
  9. print "This spans\nmultiple lines. The newlines will be\noutput as well.";
  10.  
  11. print "escaping characters is done \"Like this\".";
  12.  
  13. // You can use variables inside of a print statement
  14. $foo = "foobar";
  15. $bar = "barbaz";
  16.  
  17. print "foo is $foo"; // foo is foobar
  18.  
  19. // You can also use arrays
  20. $bar = array("value" => "foo");
  21.  
  22. print "this is {$bar['value']} !"; // this is foo !
  23.  
  24. // Using single quotes will print the variable name, not the value
  25. print 'foo is $foo'; // foo is $foo
  26.  
  27. // If you are not using any other characters, you can just print variables
  28. print $foo;          // foobar
  29.  
  30. print <<<END
  31. This uses the "here document" syntax to output
  32. multiple lines with $variable interpolation. Note
  33. that the here document terminator must appear on a
  34. line with just a semicolon no extra whitespace!
  35. END;

For a short discussion about the differences between
print() and echo(), see this FAQTs
Knowledge Base Article: http://www.faqts.com/knowledge_base/view.phtml/aid/1/fid/40

Note: Because this is a
language construct and not a function, it cannot be called using
variable functions

See also echo(), printf(),
and flush().

These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Netvouz
  • DZone
  • Reddit
  • Furl
  • NewsVine
  • Simpy
  • Slashdot
  • Spurl
  • StumbleUpon
  • YahooMyWeb
  • TailRank
  • Technorati

Home | PHP Functions | PHP print function