<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Output a string</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.parse-str.html">parse_str</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.printf.html">printf</a></div> <div class="up"><a href="ref.strings.html">String Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="function.print" class="refentry"> <div class="refnamediv"> <h1 class="refname">print</h1> <p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">print</span> — <span class="dc-title">Output a string</span></p> </div> <div class="refsect1 description" id="refsect1-function.print-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">int</span> <span class="methodname"><strong>print</strong></span> ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$arg</code></span> )</div> <p class="para rdfs-comment"> Outputs <em><code class="parameter">arg</code></em>. </p> <p class="para"> <em>print</em> is not actually a real function (it is a language construct) so you are not required to use parentheses with its argument list. </p> </div> <div class="refsect1 parameters" id="refsect1-function.print-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><em><code class="parameter">arg</code></em></span> <dd> <p class="para"> The input data. </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-function.print-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> Returns <em>1</em>, always. </p> </div> <div class="refsect1 examples" id="refsect1-function.print-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="example-4856"> <p><strong>Example #1 <em>print</em> examples</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br /></span><span style="color: #007700">print(</span><span style="color: #DD0000">"Hello World"</span><span style="color: #007700">);<br /><br />print </span><span style="color: #DD0000">"print() also works without parentheses."</span><span style="color: #007700">;<br /><br />print </span><span style="color: #DD0000">"This spans<br />multiple lines. The newlines will be<br />output as well"</span><span style="color: #007700">;<br /><br />print </span><span style="color: #DD0000">"This spans\nmultiple lines. The newlines will be\noutput as well."</span><span style="color: #007700">;<br /><br />print </span><span style="color: #DD0000">"escaping characters is done \"Like this\"."</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">// You can use variables inside a print statement<br /></span><span style="color: #0000BB">$foo </span><span style="color: #007700">= </span><span style="color: #DD0000">"foobar"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$bar </span><span style="color: #007700">= </span><span style="color: #DD0000">"barbaz"</span><span style="color: #007700">;<br /><br />print </span><span style="color: #DD0000">"foo is </span><span style="color: #0000BB">$foo</span><span style="color: #DD0000">"</span><span style="color: #007700">; </span><span style="color: #FF8000">// foo is foobar<br /><br />// You can also use arrays<br /></span><span style="color: #0000BB">$bar </span><span style="color: #007700">= array(</span><span style="color: #DD0000">"value" </span><span style="color: #007700">=> </span><span style="color: #DD0000">"foo"</span><span style="color: #007700">);<br /><br />print </span><span style="color: #DD0000">"this is </span><span style="color: #007700">{</span><span style="color: #0000BB">$bar</span><span style="color: #007700">[</span><span style="color: #DD0000">'value'</span><span style="color: #007700">]}</span><span style="color: #DD0000"> !"</span><span style="color: #007700">; </span><span style="color: #FF8000">// this is foo !<br /><br />// Using single quotes will print the variable name, not the value<br /></span><span style="color: #007700">print </span><span style="color: #DD0000">'foo is $foo'</span><span style="color: #007700">; </span><span style="color: #FF8000">// foo is $foo<br /><br />// If you are not using any other characters, you can just print variables<br /></span><span style="color: #007700">print </span><span style="color: #0000BB">$foo</span><span style="color: #007700">; </span><span style="color: #FF8000">// foobar<br /><br /></span><span style="color: #007700">print <<<END<br /></span><span style="color: #DD0000">This uses the "here document" syntax to output<br />multiple lines with </span><span style="color: #0000BB">$variable</span><span style="color: #DD0000"> interpolation. Note<br />that the here document terminator must appear on a<br />line with just a semicolon no extra whitespace!<br /></span><span style="color: #007700">END;<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> </div> </p> </div> <div class="refsect1 notes" id="refsect1-function.print-notes"> <h3 class="title">Notes</h3> <blockquote class="note"><p><strong class="note">Note</strong>: <span class="simpara">Because this is a language construct and not a function, it cannot be called using <a href="functions.variable-functions.html" class="link">variable functions</a>.</span> </p></blockquote> </div> <div class="refsect1 seealso" id="refsect1-function.print-seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"> <span class="function"><a href="function.echo.html" class="function" rel="rdfs-seeAlso">echo</a> - Output one or more strings</span></li> <li class="member"> <span class="function"><a href="function.printf.html" class="function" rel="rdfs-seeAlso">printf()</a> - Output a formatted string</span></li> <li class="member"> <span class="function"><a href="function.flush.html" class="function" rel="rdfs-seeAlso">flush()</a> - Flush the output buffer</span></li> <li class="member"><a href="language.types.string.html#language.types.string.syntax.heredoc" class="link">Heredoc syntax</a></li> </ul> </p> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.parse-str.html">parse_str</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.printf.html">printf</a></div> <div class="up"><a href="ref.strings.html">String Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>