mirror of
https://github.com/fofolee/uTools-Manuals.git
synced 2025-06-20 07:06:50 +08:00
175 lines
6.2 KiB
HTML
175 lines
6.2 KiB
HTML
<!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>在字符串所有新行之前插入 HTML 换行标记</title>
|
|
</head>
|
|
<body class="docs"><div id="layout">
|
|
<div id="layout-content"><div id="function.nl2br" class="refentry">
|
|
<div class="refnamediv">
|
|
<h1 class="refname">nl2br</h1>
|
|
<p class="verinfo">(PHP 4, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">nl2br</span> — <span class="dc-title">在字符串所有新行之前插入 HTML 换行标记</span></p>
|
|
|
|
</div>
|
|
|
|
<div class="refsect1 description" id="refsect1-function.nl2br-description">
|
|
<h3 class="title">说明</h3>
|
|
<div class="methodsynopsis dc-description">
|
|
<span class="methodname"><strong>nl2br</strong></span>
|
|
( <span class="methodparam"><span class="type">string</span> <code class="parameter">$string</code></span>
|
|
[, <span class="methodparam"><span class="type">bool</span> <code class="parameter">$is_xhtml</code><span class="initializer"> = <strong><code>TRUE</code></strong></span></span>
|
|
] ) : <span class="type">string</span></div>
|
|
|
|
<p class="para rdfs-comment">
|
|
在字符串 <code class="parameter">string</code> 所有新行之前插入 <code class="code">'<br />'</code> 或 <code class="code">'<br>'</code>,并返回。
|
|
</p>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 parameters" id="refsect1-function.nl2br-parameters">
|
|
<h3 class="title">参数</h3>
|
|
<p class="para">
|
|
<dl>
|
|
|
|
|
|
<dt>
|
|
<code class="parameter">string</code></dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
输入字符串。
|
|
</p>
|
|
</dd>
|
|
|
|
|
|
|
|
<dt>
|
|
<code class="parameter">is_xhtml</code></dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
是否使用 XHTML 兼容换行符。
|
|
</p>
|
|
</dd>
|
|
|
|
|
|
</dl>
|
|
|
|
</p>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 returnvalues" id="refsect1-function.nl2br-returnvalues">
|
|
<h3 class="title">返回值</h3>
|
|
<p class="para">
|
|
返回调整后的字符串。
|
|
</p>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 examples" id="refsect1-function.nl2br-examples">
|
|
<h3 class="title">范例</h3>
|
|
<p class="para">
|
|
<div class="example" id="example-5925">
|
|
<p><strong>Example #1 <span class="function"><strong>nl2br()</strong></span> 使用范例</strong></p>
|
|
<div class="example-contents">
|
|
<div class="phpcode"><pre><span style="color: #000000">
|
|
<span style="color: #0000BB"><?php<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">nl2br</span><span style="color: #007700">(</span><span style="color: #DD0000">"foo isn't\n bar"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?></span>
|
|
</span>
|
|
</pre></div>
|
|
</div>
|
|
|
|
<div class="example-contents"><p>以上例程会输出:</p></div>
|
|
<div class="example-contents screen">
|
|
<div class="cdata"><pre>
|
|
foo isn't<br />
|
|
bar
|
|
</pre></div>
|
|
</div>
|
|
</div>
|
|
<div class="example" id="example-5926">
|
|
<p><strong>Example #2 使用 <code class="parameter">is_xhtml</code> 生成合法的 HTML 标记</strong></p>
|
|
<div class="example-contents">
|
|
<div class="phpcode"><pre><span style="color: #000000">
|
|
<span style="color: #0000BB"><?php<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">nl2br</span><span style="color: #007700">(</span><span style="color: #DD0000">"Welcome\r\nThis is my HTML document"</span><span style="color: #007700">, </span><span style="color: #0000BB">false</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?></span>
|
|
</span>
|
|
</pre></div>
|
|
</div>
|
|
|
|
<div class="example-contents"><p>以上例程会输出:</p></div>
|
|
<div class="example-contents screen">
|
|
<div class="cdata"><pre>
|
|
Welcome<br>
|
|
This is my HTML document
|
|
</pre></div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="example" id="example-5927">
|
|
<p><strong>Example #3 各种换行分隔符</strong></p>
|
|
<div class="example-contents">
|
|
<div class="phpcode"><pre><span style="color: #000000">
|
|
<span style="color: #0000BB"><?php<br />$string </span><span style="color: #007700">= </span><span style="color: #DD0000">"This\r\nis\n\ra\nstring\r"</span><span style="color: #007700">;<br />echo </span><span style="color: #0000BB">nl2br</span><span style="color: #007700">(</span><span style="color: #0000BB">$string</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?></span>
|
|
</span>
|
|
</pre></div>
|
|
</div>
|
|
|
|
<div class="example-contents"><p>以上例程会输出:</p></div>
|
|
<div class="example-contents screen">
|
|
<div class="cdata"><pre>
|
|
This<br />
|
|
is<br />
|
|
a<br />
|
|
string<br />
|
|
</pre></div>
|
|
</div>
|
|
</div>
|
|
</p>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 changelog" id="refsect1-function.nl2br-changelog">
|
|
<h3 class="title">更新日志</h3>
|
|
<p class="para">
|
|
<table class="doctable informaltable">
|
|
|
|
<thead>
|
|
<tr>
|
|
<th>版本</th>
|
|
<th>说明</th>
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody class="tbody">
|
|
<tr>
|
|
<td>5.3.0</td>
|
|
<td>
|
|
新增可选的 <code class="parameter">is_xhtml</code> 参数。在此之前,总是插入 '<br />'。
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
</p>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 seealso" id="refsect1-function.nl2br-seealso">
|
|
<h3 class="title">参见</h3>
|
|
<p class="para">
|
|
<ul class="simplelist">
|
|
<li class="member"><span class="function"><a href="htmlspecialchars.html" class="function" rel="rdfs-seeAlso">htmlspecialchars()</a> - 将特殊字符转换为 HTML 实体</span></li>
|
|
<li class="member"><span class="function"><a href="htmlentities.html" class="function" rel="rdfs-seeAlso">htmlentities()</a> - 将字符转换为 HTML 转义字符</span></li>
|
|
<li class="member"><span class="function"><a href="wordwrap.html" class="function" rel="rdfs-seeAlso">wordwrap()</a> - 打断字符串为指定数量的字串</span></li>
|
|
<li class="member"><span class="function"><a href="str_replace.html" class="function" rel="rdfs-seeAlso">str_replace()</a> - 子字符串替换</span></li>
|
|
</ul>
|
|
</p>
|
|
</div>
|
|
|
|
|
|
</div></div></div></body></html> |