Sophie

Sophie

distrib > Mandriva > 2008.1 > x86_64 > by-pkgid > 05cd670d8a02b2b4a0ffb1756f2e8308 > files > 9901

php-manual-zh-5.2.4-1mdv2008.1.noarch.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML
><HEAD
><TITLE
>strip_tags</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
REL="HOME"
TITLE="PHP 手册"
HREF="index.html"><LINK
REL="UP"
TITLE="String 字符串处理函数"
HREF="ref.strings.html"><LINK
REL="PREVIOUS"
TITLE="strcspn"
HREF="function.strcspn.html"><LINK
REL="NEXT"
TITLE="stripcslashes"
HREF="function.stripcslashes.html"><META
HTTP-EQUIV="Content-type"
CONTENT="text/html; charset=UTF-8"></HEAD
><BODY
CLASS="refentry"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>PHP 手册</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="function.strcspn.html"
ACCESSKEY="P"
>上一页</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="function.stripcslashes.html"
ACCESSKEY="N"
>下一页</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><H1
><A
NAME="function.strip-tags"
></A
>strip_tags</H1
><DIV
CLASS="refnamediv"
><A
NAME="AEN227536"
></A
><P
>    (PHP 3 &#62;= 3.0.8, PHP 4, PHP 5)</P
>strip_tags&nbsp;--&nbsp;Strip HTML and PHP tags from a string</DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN227539"
></A
><H2
>Description</H2
>string <B
CLASS="methodname"
>strip_tags</B
> ( string str [, string allowable_tags] )<BR
></BR
><P
>&#13;     This function tries to return a string with all HTML and PHP tags
     stripped from a given <CODE
CLASS="parameter"
>str</CODE
>.  It uses
     the same tag stripping state machine as the
     <A
HREF="function.fgetss.html"
><B
CLASS="function"
>fgetss()</B
></A
> function.
    </P
><P
>&#13;     You can use the optional second parameter to specify tags which
     should not be stripped.
     <DIV
CLASS="note"
><BLOCKQUOTE
CLASS="note"
><P
><B
>注意: </B
>
       <CODE
CLASS="parameter"
>allowable_tags</CODE
> was added in PHP 3.0.13
       and PHP 4.0.0.
      </P
><P
>&#13;       Since PHP 4.3.0, HTML comments are also stripped. This is hardcoded and can
       not be changed with <CODE
CLASS="parameter"
>allowable_tags</CODE
>.
      </P
></BLOCKQUOTE
></DIV
>
     <DIV
CLASS="warning"
><P
></P
><TABLE
CLASS="warning"
BORDER="1"
WIDTH="100%"
><TR
><TD
ALIGN="CENTER"
><B
>警告</B
></TD
></TR
><TR
><TD
ALIGN="LEFT"
><P
>&#13;         Because <B
CLASS="function"
>strip_tags()</B
> does not actually validate the
         HTML, partial, or broken tags can result in the removal of more
         text/data than expected.
       </P
></TD
></TR
></TABLE
></DIV
>
     <DIV
CLASS="warning"
><P
></P
><TABLE
CLASS="warning"
BORDER="1"
WIDTH="100%"
><TR
><TD
ALIGN="CENTER"
><B
>警告</B
></TD
></TR
><TR
><TD
ALIGN="LEFT"
><P
>&#13;       This function does not modify any attributes on the tags that you allow
       using <CODE
CLASS="parameter"
>allowable_tags</CODE
>, including the
       <TT
CLASS="literal"
>style</TT
> and <TT
CLASS="literal"
>onmouseover</TT
> attributes
       that a mischievous user may abuse when posting text that will be shown
       to other users.
      </P
></TD
></TR
></TABLE
></DIV
>
    </P
><P
>&#13;     <TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN227568"
></A
><P
><B
>例 1. <B
CLASS="function"
>strip_tags()</B
> example</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><code><font color="#000000">
<font color="#0000BB">&lt;?php<br />$text </font><font color="#007700">= </font><font color="#DD0000">'&lt;p&gt;Test paragraph.&lt;/p&gt;&lt;!-- Comment --&gt; &lt;a href="#fragment"&gt;Other text&lt;/a&gt;'</font><font color="#007700">;<br />echo </font><font color="#0000BB">strip_tags</font><font color="#007700">(</font><font color="#0000BB">$text</font><font color="#007700">);<br />echo </font><font color="#DD0000">"\n"</font><font color="#007700">;<br /><br /></font><font color="#FF8000">// Allow &lt;p&gt; and &lt;a&gt;<br /></font><font color="#007700">echo </font><font color="#0000BB">strip_tags</font><font color="#007700">(</font><font color="#0000BB">$text</font><font color="#007700">, </font><font color="#DD0000">'&lt;p&gt;&lt;a&gt;'</font><font color="#007700">);<br /></font><font color="#0000BB">?&gt;</font>
</font>
</code></TD
></TR
></TABLE
><P
>上例将输出:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="screen"
>Test paragraph. Other text
&#60;p&#62;Test paragraph.&#60;/p&#62; &#60;a href="#fragment"&#62;Other text&#60;/a&#62;</PRE
></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
>
    </P
><P
>&#13;     <B
CLASS="function"
>strip_tags()</B
> has been binary safe since PHP 5.0.0
    </P
><P
>&#13;     See also <A
HREF="function.htmlspecialchars.html"
><B
CLASS="function"
>htmlspecialchars()</B
></A
>.
    </P
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="function.strcspn.html"
ACCESSKEY="P"
>上一页</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>起始页</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="function.stripcslashes.html"
ACCESSKEY="N"
>下一页</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>strcspn</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="ref.strings.html"
ACCESSKEY="U"
>上一级</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>stripcslashes</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>