<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML ><HEAD ><TITLE >db2_escape_string</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK REL="HOME" TITLE="PHP 手册" HREF="index.html"><LINK REL="UP" TITLE="IBM DB2, Cloudscape and Apache Derby Functions" HREF="ref.ibm-db2.html"><LINK REL="PREVIOUS" TITLE="db2_cursor_type" HREF="function.db2-cursor-type.html"><LINK REL="NEXT" TITLE="db2_exec" HREF="function.db2-exec.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.db2-cursor-type.html" ACCESSKEY="P" >上一页</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.db2-exec.html" ACCESSKEY="N" >下一页</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><H1 ><A NAME="function.db2-escape-string" ></A >db2_escape_string</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN80458" ></A ><P > (no version information, might be only in CVS)</P >db2_escape_string -- Used to escape certain characters. </DIV ><DIV CLASS="refsect1" ><A NAME="AEN80461" ></A ><H2 >说明</H2 >string <B CLASS="methodname" >db2_escape_string</B > ( string string_literal )<BR ></BR ><P > Prepends backslashes to special characters in the string argument. </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN80470" ></A ><H2 >参数</H2 ><P > <P ></P ><DIV CLASS="variablelist" ><DL ><DT ><CODE CLASS="parameter" >string_literal</CODE ></DT ><DD ><P > The string that contains special characters that need to be modified. Characters that are prepended with a backslash are <TT CLASS="literal" >\x00</TT >, <TT CLASS="literal" >\n</TT >, <TT CLASS="literal" >\r</TT >, <TT CLASS="literal" >\</TT >, <TT CLASS="literal" >'</TT >, <TT CLASS="literal" >"</TT > and <TT CLASS="literal" >\x1a</TT >. </P ></DD ></DL ></DIV > </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN80486" ></A ><H2 >返回值</H2 ><P > Returns <CODE CLASS="parameter" >string_literal</CODE > with the special characters noted above prepended with backslashes. </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN80490" ></A ><H2 >范例</H2 ><P > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN80493" ></A ><P ><B >例 1. A <B CLASS="function" >db2_escape_string()</B > example</B ></P ><P > Result of using the <B CLASS="function" >db2_escape_string()</B > function </P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br /><br />$conn </font><font color="#007700">= </font><font color="#0000BB">db2_connect</font><font color="#007700">(</font><font color="#0000BB">$database</font><font color="#007700">, </font><font color="#0000BB">$user</font><font color="#007700">, </font><font color="#0000BB">$password</font><font color="#007700">);<br /><br />if (</font><font color="#0000BB">$conn</font><font color="#007700">) {<br /> </font><font color="#0000BB">$str</font><font color="#007700">[</font><font color="#0000BB">0</font><font color="#007700">] = </font><font color="#DD0000">"All characters: \x00 , \n , \r , \ , ' , \" , \x1a ."</font><font color="#007700">;<br /> </font><font color="#0000BB">$str</font><font color="#007700">[</font><font color="#0000BB">1</font><font color="#007700">] = </font><font color="#DD0000">"Backslash (\). Single quote ('). Double quote (\")"</font><font color="#007700">;<br /> </font><font color="#0000BB">$str</font><font color="#007700">[</font><font color="#0000BB">2</font><font color="#007700">] = </font><font color="#DD0000">"The NULL character \0 must be quoted as well"</font><font color="#007700">;<br /> </font><font color="#0000BB">$str</font><font color="#007700">[</font><font color="#0000BB">3</font><font color="#007700">] = </font><font color="#DD0000">"Intersting characters: \x1a , \x00 ."</font><font color="#007700">;<br /> </font><font color="#0000BB">$str</font><font color="#007700">[</font><font color="#0000BB">4</font><font color="#007700">] = </font><font color="#DD0000">"Nothing to quote"</font><font color="#007700">;<br /> </font><font color="#0000BB">$str</font><font color="#007700">[</font><font color="#0000BB">5</font><font color="#007700">] = </font><font color="#0000BB">200676</font><font color="#007700">;<br /> </font><font color="#0000BB">$str</font><font color="#007700">[</font><font color="#0000BB">6</font><font color="#007700">] = </font><font color="#DD0000">""</font><font color="#007700">;<br /><br /> foreach( </font><font color="#0000BB">$str </font><font color="#007700">as </font><font color="#0000BB">$string </font><font color="#007700">) {<br /> echo </font><font color="#DD0000">"db2_escape_string: " </font><font color="#007700">. </font><font color="#0000BB">db2_escape_string</font><font color="#007700">(</font><font color="#0000BB">$string</font><font color="#007700">). </font><font color="#DD0000">"\n"</font><font color="#007700">;<br /> }<br />}<br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ><P >上例将输出:</P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="screen" >db2_escape_string: All characters: \0 , \n , \r , \\ , \' , \" , \Z . db2_escape_string: Backslash (\\). Single quote (\'). Double quote (\") db2_escape_string: The NULL character \0 must be quoted as well db2_escape_string: Intersting characters: \Z , \0 . db2_escape_string: Nothing to quote db2_escape_string: 200676 db2_escape_string:</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN80501" ></A ><H2 >参见</H2 ><P > <P ></P ><TABLE BORDER="0" ><TBODY ><TR ><TD ><A HREF="function.db2-prepare.html" ><B CLASS="function" >db2_prepare()</B ></A ></TD ></TR ></TBODY ></TABLE ><P ></P > </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.db2-cursor-type.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.db2-exec.html" ACCESSKEY="N" >下一页</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >db2_cursor_type</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="ref.ibm-db2.html" ACCESSKEY="U" >上一级</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >db2_exec</TD ></TR ></TABLE ></DIV ></BODY ></HTML >