<!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>Used to escape certain characters</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.db2-cursor-type.html">db2_cursor_type</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.db2-exec.html">db2_exec</a></div> <div class="up"><a href="ref.ibm-db2.html">IBM DB2 Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="function.db2-escape-string" class="refentry"> <div class="refnamediv"> <h1 class="refname">db2_escape_string</h1> <p class="verinfo">(PECL ibm_db2 >= 1.6.0)</p><p class="refpurpose"><span class="refname">db2_escape_string</span> — <span class="dc-title"> Used to escape certain characters </span></p> </div> <div class="refsect1 description" id="refsect1-function.db2-escape-string-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">string</span> <span class="methodname"><strong>db2_escape_string</strong></span> ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$string_literal</code></span> )</div> <p class="para rdfs-comment"> Prepends backslashes to special characters in the string argument. </p> </div> <div class="refsect1 parameters" id="refsect1-function.db2-escape-string-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><em><code class="parameter">string_literal</code></em></span> <dd> <p class="para"> The string that contains special characters that need to be modified. Characters that are prepended with a backslash are <em>\x00</em>, <em>\n</em>, <em>\r</em>, <em>\</em>, <em>'</em>, <em>"</em> and <em>\x1a</em>. </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-function.db2-escape-string-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> Returns <em><code class="parameter">string_literal</code></em> with the special characters noted above prepended with backslashes. </p> </div> <div class="refsect1 examples" id="refsect1-function.db2-escape-string-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="example-1152"> <p><strong>Example #1 A <span class="function"><strong>db2_escape_string()</strong></span> example</strong></p> <div class="example-contents"><p> Result of using the <span class="function"><strong>db2_escape_string()</strong></span> function </p></div> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br /><br />$conn </span><span style="color: #007700">= </span><span style="color: #0000BB">db2_connect</span><span style="color: #007700">(</span><span style="color: #0000BB">$database</span><span style="color: #007700">, </span><span style="color: #0000BB">$user</span><span style="color: #007700">, </span><span style="color: #0000BB">$password</span><span style="color: #007700">);<br /><br />if (</span><span style="color: #0000BB">$conn</span><span style="color: #007700">) {<br /> </span><span style="color: #0000BB">$str</span><span style="color: #007700">[</span><span style="color: #0000BB">0</span><span style="color: #007700">] = </span><span style="color: #DD0000">"All characters: \x00 , \n , \r , \ , ' , \" , \x1a ."</span><span style="color: #007700">;<br /> </span><span style="color: #0000BB">$str</span><span style="color: #007700">[</span><span style="color: #0000BB">1</span><span style="color: #007700">] = </span><span style="color: #DD0000">"Backslash (\). Single quote ('). Double quote (\")"</span><span style="color: #007700">;<br /> </span><span style="color: #0000BB">$str</span><span style="color: #007700">[</span><span style="color: #0000BB">2</span><span style="color: #007700">] = </span><span style="color: #DD0000">"The NULL character \0 must be quoted as well"</span><span style="color: #007700">;<br /> </span><span style="color: #0000BB">$str</span><span style="color: #007700">[</span><span style="color: #0000BB">3</span><span style="color: #007700">] = </span><span style="color: #DD0000">"Intersting characters: \x1a , \x00 ."</span><span style="color: #007700">;<br /> </span><span style="color: #0000BB">$str</span><span style="color: #007700">[</span><span style="color: #0000BB">4</span><span style="color: #007700">] = </span><span style="color: #DD0000">"Nothing to quote"</span><span style="color: #007700">;<br /> </span><span style="color: #0000BB">$str</span><span style="color: #007700">[</span><span style="color: #0000BB">5</span><span style="color: #007700">] = </span><span style="color: #0000BB">200676</span><span style="color: #007700">;<br /> </span><span style="color: #0000BB">$str</span><span style="color: #007700">[</span><span style="color: #0000BB">6</span><span style="color: #007700">] = </span><span style="color: #DD0000">""</span><span style="color: #007700">;<br /><br /> foreach( </span><span style="color: #0000BB">$str </span><span style="color: #007700">as </span><span style="color: #0000BB">$string </span><span style="color: #007700">) {<br /> echo </span><span style="color: #DD0000">"db2_escape_string: " </span><span style="color: #007700">. </span><span style="color: #0000BB">db2_escape_string</span><span style="color: #007700">(</span><span style="color: #0000BB">$string</span><span style="color: #007700">). </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /> }<br />}<br /></span><span style="color: #0000BB">?></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> 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></div> </div> </div> </p> </div> <div class="refsect1 seealso" id="refsect1-function.db2-escape-string-seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"> <span class="function"><a href="function.db2-prepare.html" class="function" rel="rdfs-seeAlso">db2_prepare()</a> - Prepares an SQL statement to be executed</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.db2-cursor-type.html">db2_cursor_type</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.db2-exec.html">db2_exec</a></div> <div class="up"><a href="ref.ibm-db2.html">IBM DB2 Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>