📄 function.print.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head> <title>Output a string</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body><div 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"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">int</span> <span class="methodname"><b><b>print</b></b></span> ( <span class="methodparam"><span class="type">string</span> <tt class="parameter">$arg</tt></span> )</div> <p class="para rdfs-comment"> Outputs <i><tt class="parameter">arg</tt></i>. </p> <p class="para"> <b>print()</b> is not actually a real function (it is a language construct) so you are not required to use parentheses with its argument list. </p> <p class="para"> For a short discussion about the differences between <b>print()</b> and <a href="function.echo.html" class="function">echo()</a>, see this FAQTs Knowledge Base Article: <a href="http://www.faqts.com/knowledge_base/view.phtml/aid/1/fid/40" class="link external">» http://www.faqts.com/knowledge_base/view.phtml/aid/1/fid/40</a> </p> </div> <div class="refsect1 parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><i><tt class="parameter">arg</tt></i></span> <dd> <p class="para"> The input data. </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> Returns <i>1</i>, always. </p> </div> <div class="refsect1 examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example"> <p><b>Example #1 <b>print()</b> examples</b></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 of 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 $foo"</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 {$bar['value']} !"</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: #0000BB">This uses the "here document" syntax to output<br />multiple lines with $variable 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"> <h3 class="title">Notes</h3> <blockquote><p><b class="note">Note</b>: <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"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"><a href="function.echo.html" class="function" rel="rdfs-seeAlso">echo()</a></li> <li class="member"><a href="function.printf.html" class="function" rel="rdfs-seeAlso">printf()</a></li> <li class="member"><a href="function.flush.html" class="function" rel="rdfs-seeAlso">flush()</a></li> </ul> </p> </div></div><hr /><div 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>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -