Sophie

Sophie

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

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>Strip HTML and PHP tags from a string</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.strcspn.html">strcspn</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.stripcslashes.html">stripcslashes</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.strip-tags" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">strip_tags</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">strip_tags</span> &mdash; <span class="dc-title">Strip HTML and PHP tags from a string</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.strip-tags-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">string</span> <span class="methodname"><strong>strip_tags</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$str</code></span>
   [, <span class="methodparam"><span class="type">string</span> <code class="parameter">$allowable_tags</code></span>
  ] )</div>

  <p class="para rdfs-comment">
   This function tries to return a string with all NULL bytes, HTML and PHP tags stripped
   from a given <code class="parameter">str</code>.  It uses the same tag stripping
   state machine as the <span class="function"><a href="function.fgetss.html" class="function">fgetss()</a></span> function.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.strip-tags-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">allowable_tags</code></dt>

     <dd>

      <p class="para">
       You can use the optional second parameter to specify tags which should
       not be stripped.
      </p>
      <blockquote class="note"><p><strong class="note">Note</strong>: 
       <p class="para">
        HTML comments and PHP tags are also stripped. This is hardcoded and
        can not be changed with <code class="parameter">allowable_tags</code>.
       </p>
      </p></blockquote>
      <blockquote class="note"><p><strong class="note">Note</strong>: 
       <p class="para">
        In PHP 5.3.4 and later, self-closing
        XHTML tags are ignored and only non-self-closing tags should be used in
        <code class="parameter">allowable_tags</code>. For example,
        to allow both <em>&lt;br&gt;</em> and
        <em>&lt;br/&gt;</em>, you should use:
       </p>
       <div class="informalexample">
        <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />strip_tags</span><span style="color: #007700">(</span><span style="color: #0000BB">$input</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'&lt;br&gt;'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
        </div>

       </div>
      </p></blockquote>
     </dd>

    
   </dl>

  </p>
 </div>


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


 <div class="refsect1 changelog" id="refsect1-function.strip-tags-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.4</td>
       <td>
        <span class="function"><strong>strip_tags()</strong></span> ignores self-closing XHTML
        tags in
        <code class="parameter">allowable_tags</code>.
       </td>
      </tr>

      <tr>
       <td>5.0.0</td>
       <td>
        <span class="function"><strong>strip_tags()</strong></span> is now binary safe.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.strip-tags-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-6095">
    <p><strong>Example #1 <span class="function"><strong>strip_tags()</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">'&lt;p&gt;Test&nbsp;paragraph.&lt;/p&gt;&lt;!--&nbsp;Comment&nbsp;--&gt;&nbsp;&lt;a&nbsp;href="#fragment"&gt;Other&nbsp;text&lt;/a&gt;'</span><span style="color: #007700">;<br />echo&nbsp;</span><span style="color: #0000BB">strip_tags</span><span style="color: #007700">(</span><span style="color: #0000BB">$text</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">//&nbsp;Allow&nbsp;&lt;p&gt;&nbsp;and&nbsp;&lt;a&gt;<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">strip_tags</span><span style="color: #007700">(</span><span style="color: #0000BB">$text</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'&lt;p&gt;&lt;a&gt;'</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>
Test paragraph. Other text
&lt;p&gt;Test paragraph.&lt;/p&gt; &lt;a href=&quot;#fragment&quot;&gt;Other text&lt;/a&gt;
</pre></div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.strip-tags-notes">
  <h3 class="title">Notes</h3>
  <div class="warning"><strong class="warning">Warning</strong>
   <p class="para">
    Because <span class="function"><strong>strip_tags()</strong></span> does not actually validate the
    HTML, partial or broken tags can result in the removal of more
    text/data than expected.
   </p>
  </div>
  <div class="warning"><strong class="warning">Warning</strong>
   <p class="para">
    This function does not modify any attributes on the tags that you allow
    using <code class="parameter">allowable_tags</code>, including the
    <em>style</em> and <em>onmouseover</em> attributes
    that a mischievous user may abuse when posting text that will be shown
    to other users.
   </p>
  </div>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    Tag names within the input HTML that are greater than 1023 bytes in length
    will be treated as though they are invalid, regardless of the
    <code class="parameter">allowable_tags</code> parameter.
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.strip-tags-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>
   </ul>
  </p>
 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.strcspn.html">strcspn</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.stripcslashes.html">stripcslashes</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>