Sophie

Sophie

distrib > Mageia > 7 > i586 > by-pkgid > 2b917e0437961edec048f1d15e2d7449 > files > 5258

php-manual-en-7.2.11-1.mga7.noarch.rpm

<!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>Inserts HTML line breaks before all newlines in a string</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.nl-langinfo.html">nl_langinfo</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.number-format.html">number_format</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.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> &mdash; <span class="dc-title">Inserts HTML line breaks before all newlines in a string</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.nl2br-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">string</span> <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>
  ] )</div>

  <p class="para rdfs-comment">
   Returns <code class="parameter">string</code> with <code class="code">&lt;br /&gt;</code> or 
   <code class="code">&lt;br&gt;</code> inserted before all newlines (<em>\r\n</em>,
   <em>\n\r</em>, <em>\n</em> and <em>\r</em>).
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.nl2br-parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   <dl>

    
     <dt>
<code class="parameter">string</code></dt>

     <dd>

      <p class="para">
       The input string.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">is_xhtml</code></dt>

     <dd>

      <p class="para">
       Whether to use XHTML compatible line breaks or not.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.nl2br-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   Returns the altered string.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.nl2br-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-6054">
    <p><strong>Example #1 Using <span class="function"><strong>nl2br()</strong></span></strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">nl2br</span><span style="color: #007700">(</span><span style="color: #DD0000">"foo&nbsp;isn't\n&nbsp;bar"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>The above example will output:</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
foo isn&#039;t&lt;br /&gt;
 bar
</pre></div>
    </div>
   </div>
   <div class="example" id="example-6055">
    <p><strong>Example #2 Generating valid HTML markup using the <code class="parameter">is_xhtml</code> parameter</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">nl2br</span><span style="color: #007700">(</span><span style="color: #DD0000">"Welcome\r\nThis&nbsp;is&nbsp;my&nbsp;HTML&nbsp;document"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">false</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>The above example will output:</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
Welcome&lt;br&gt;
This is my HTML document
</pre></div>
    </div>
   </div>
   <div class="example" id="example-6056">
    <p><strong>Example #3 Various newline separators</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$string&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"This\r\nis\n\ra\nstring\r"</span><span style="color: #007700">;<br />echo&nbsp;</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">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>The above example will output:</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
This&lt;br /&gt;
is&lt;br /&gt;
a&lt;br /&gt;
string&lt;br /&gt;
</pre></div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.nl2br-changelog">
  <h3 class="title">Changelog</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>Version</th>
       <th>Description</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>5.3.0</td>
       <td>
         Added the optional <code class="parameter">is_xhtml</code> parameter. Before
         this version &#039;&lt;br /&gt;&#039; was always inserted.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.nl2br-seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.htmlspecialchars.html" class="function" rel="rdfs-seeAlso">htmlspecialchars()</a> - Convert special characters to HTML entities</span></li>
    <li class="member"><span class="function"><a href="function.htmlentities.html" class="function" rel="rdfs-seeAlso">htmlentities()</a> - Convert all applicable characters to HTML entities</span></li>
    <li class="member"><span class="function"><a href="function.wordwrap.html" class="function" rel="rdfs-seeAlso">wordwrap()</a> - Wraps a string to a given number of characters</span></li>
    <li class="member"><span class="function"><a href="function.str-replace.html" class="function" rel="rdfs-seeAlso">str_replace()</a> - Replace all occurrences of the search string with the replacement string</span></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.nl-langinfo.html">nl_langinfo</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.number-format.html">number_format</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>