Sophie

Sophie

distrib > Mageia > 4 > i586 > by-pkgid > f800694edefe91adea2624f711a41a2d > files > 6081

php-manual-en-5.5.7-1.mga4.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)</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 <em><code class="parameter">str</code></em>.  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>

     <span class="term"><em><code class="parameter">str</code></em></span>
     <dd>

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

    </dt>

    <dt>

     <span class="term"><em><code class="parameter">allowable_tags</code></em></span>
     <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 <em><code class="parameter">allowable_tags</code></em>.
       </p>
      </p></blockquote>
      <blockquote class="note"><p><strong class="note">Note</strong>: 
       <p class="para">
        This parameter should not contain whitespace.
         <span class="function"><strong>strip_tags()</strong></span> sees a tag as a case-insensitive
        string between <em>&lt;</em> and the first whitespace or
        <em>&gt;</em>. It means that
        <em>strip_tags(&quot;&lt;br/&gt;&quot;, &quot;&lt;br&gt;&quot;)</em> returns an
        empty string.
       </p>
      </p></blockquote>
     </dd>

    </dt>

   </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.0.0</td>
       <td>
         <span class="function"><strong>strip_tags()</strong></span> is now binary safe.
       </td>
      </tr>

      <tr>
       <td>4.3.0</td>
       <td>
        HTML comments are now always stripped.
       </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-4886">
    <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 <em><code class="parameter">allowable_tags</code></em>, 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
    <em><code class="parameter">allowable_tags</code></em> 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>