Sophie

Sophie

distrib > Mageia > 7 > x86_64 > by-pkgid > 2b917e0437961edec048f1d15e2d7449 > files > 7126

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>Wraps a string to a given number of characters</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.vsprintf.html">vsprintf</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="changelog.strings.html">Changelog</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.wordwrap" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">wordwrap</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.0.2, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">wordwrap</span> &mdash; <span class="dc-title">Wraps a string to a given number of characters</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.wordwrap-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">string</span> <span class="methodname"><strong>wordwrap</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$str</code></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$width</code><span class="initializer"> = 75</span></span>
   [, <span class="methodparam"><span class="type">string</span> <code class="parameter">$break</code><span class="initializer"> = &quot;\n&quot;</span></span>
   [, <span class="methodparam"><span class="type">bool</span> <code class="parameter">$cut</code><span class="initializer"> = <strong><code>FALSE</code></strong></span></span>
  ]]] )</div>

  <p class="para rdfs-comment">
   Wraps a string to a given number of characters using a string break
   character.
  </p>
 </div>


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

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

     <dd>

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

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

     <dd>

      <p class="para">
       The number of characters at which the string will be wrapped.
      </p>
     </dd>

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

     <dd>

      <p class="para">
       The line is broken using the optional
       <code class="parameter">break</code> parameter.
      </p>
     </dd>

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

     <dd>

      <p class="para">
       If the <code class="parameter">cut</code> is set to <strong><code>TRUE</code></strong>, the string is
       always wrapped at or before the specified <code class="parameter">width</code>.  So if you have
       a word that is larger than the given width, it is broken apart.
       (See second example). When <strong><code>FALSE</code></strong> the function does not split the word
       even if the <code class="parameter">width</code> is smaller than the word width.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.wordwrap-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   Returns the given string wrapped at the specified length.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.wordwrap-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-6138">
    <p><strong>Example #1 <span class="function"><strong>wordwrap()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$text&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"The&nbsp;quick&nbsp;brown&nbsp;fox&nbsp;jumped&nbsp;over&nbsp;the&nbsp;lazy&nbsp;dog."</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$newtext&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">wordwrap</span><span style="color: #007700">(</span><span style="color: #0000BB">$text</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">20</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"&lt;br&nbsp;/&gt;\n"</span><span style="color: #007700">);<br /><br />echo&nbsp;</span><span style="color: #0000BB">$newtext</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>
The quick brown fox&lt;br /&gt;
jumped over the lazy&lt;br /&gt;
dog.
</pre></div>
    </div>
   </div>
   <div class="example" id="example-6139">
    <p><strong>Example #2 <span class="function"><strong>wordwrap()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$text&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"A&nbsp;very&nbsp;long&nbsp;woooooooooooord."</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$newtext&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">wordwrap</span><span style="color: #007700">(</span><span style="color: #0000BB">$text</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">8</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">true</span><span style="color: #007700">);<br /><br />echo&nbsp;</span><span style="color: #DD0000">"</span><span style="color: #0000BB">$newtext</span><span style="color: #DD0000">\n"</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>
A very
long
wooooooo
ooooord.
</pre></div>
    </div>
   </div>
   <div class="example" id="example-6140">
    <p><strong>Example #3 <span class="function"><strong>wordwrap()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$text&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"A&nbsp;very&nbsp;long&nbsp;woooooooooooooooooord.&nbsp;and&nbsp;something"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$newtext&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">wordwrap</span><span style="color: #007700">(</span><span style="color: #0000BB">$text</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">8</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">false</span><span style="color: #007700">);<br /><br />echo&nbsp;</span><span style="color: #DD0000">"</span><span style="color: #0000BB">$newtext</span><span style="color: #DD0000">\n"</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>
A very
long
woooooooooooooooooord.
and
something
</pre></div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.wordwrap-seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.nl2br.html" class="function" rel="rdfs-seeAlso">nl2br()</a> - Inserts HTML line breaks before all newlines in a string</span></li>
    <li class="member"><span class="function"><a href="function.chunk-split.html" class="function" rel="rdfs-seeAlso">chunk_split()</a> - Split a string into smaller chunks</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.vsprintf.html">vsprintf</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="changelog.strings.html">Changelog</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>