⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 faq.using.html

📁 php的帮助文档,涉及到PHP的案例和基本语法,以及实际应用内容
💻 HTML
📖 第 1 页 / 共 3 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head>  <title>Using PHP</title>  <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="faq.build.html">Build Problems</a></div> <div class="next" style="text-align: right; float: right;"><a href="faq.html.html">PHP and HTML</a></div> <div class="up"><a href="faq.html">FAQ</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div><hr /><div>  <h1>Using PHP</h1>    <p class="para">   This section gathers many common errors that you may face    while writing PHP scripts.  </p>  <div class="qandaset"><ol class="qandaset_questions"><li><a href="#faq.using.anyform">           I would like to write a generic PHP script that can handle data coming       from any form. How do I know which POST method variables are available?         </a></li><li><a href="#faq.using.addslashes">           I need to convert all single-quotes (&#039;) to a backslash       followed by a single-quote (\&#039;). How can I do this with a       regular expression?  I&#039;d also like to convert &quot; to \&quot; and      \ to \\.         </a></li><li><a href="#faq.using.stripslashes">           All my &quot; turn into \&quot; and my &#039; turn into \&#039;, how do I get rid of all       these unwanted backslashes?  How and why did they get there?         </a></li><li><a href="#faq.register-globals">           How does the PHP directive register_globals affect me?         </a></li><li><a href="#faq.using.wrong-order">           When I do the following, the output is printed in       the wrong order:      &lt;?phpfunction&nbsp;myfunc($argument){&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;$argument&nbsp;+&nbsp;10;}$variable&nbsp;=&nbsp;10;echo&nbsp;"myfunc($variable)&nbsp;=&nbsp;"&nbsp;.&nbsp;myfunc($variable);?&gt;         what&#039;s going on?         </a></li><li><a href="#faq.using.newlines">           Hey, what happened to my newlines?      &lt;pre&gt;&lt;?php&nbsp;echo&nbsp;"This&nbsp;should&nbsp;be&nbsp;the&nbsp;first&nbsp;line.";&nbsp;?&gt;&lt;?php&nbsp;echo&nbsp;"This&nbsp;should&nbsp;show&nbsp;up&nbsp;after&nbsp;the&nbsp;new&nbsp;line&nbsp;above.";&nbsp;?&gt;&lt;/pre&gt;               </a></li><li><a href="#faq.using.headers-sent">           I get the message &#039;Warning: Cannot send session cookie - headers already      sent...&#039; or &#039;Cannot add header information - headers already sent...&#039;.         </a></li><li><a href="#faq.using.header">           I need to access information in the request header directly.       How can I do this?         </a></li><li><a href="#faq.using.authentication">           When I try to use authentication with IIS I get &#039;No Input file specified&#039;.         </a></li><li><a href="#faq.using.iis.sharing">           Windows: I can&#039;t access files shared on another computer using IIS         </a></li><li><a href="#faq.using.netscape">           My PHP script works on IE and Lynx, but on Netscape some of      my output is missing. When I do a &quot;View Source&quot; I see the       content in IE but not in Netscape.         </a></li><li><a href="#faq.using.mixml">           How am I supposed to mix XML and PHP? It complains       about my &lt;?xml tags!         </a></li><li><a href="#faq.using.editor">           How can I use PHP with FrontPage or some other HTML editor      that insists on moving my code around?         </a></li><li><a href="#faq.using.variables">           Where can I find a complete list of variables are available to me       in PHP?         </a></li><li><a href="#faq.using.freepdf">           How can I generate PDF files without using the non-free and       commercial libraries like       PDFLib?  I&#039;d like something that&#039;s       free and doesn&#039;t require external PDF libraries.         </a></li><li><a href="#faq.using.cgi-vars">           I&#039;m trying to access one of the standard CGI      variables (such as $DOCUMENT_ROOT or $HTTP_REFERER) in a user-defined      function, and it can&#039;t seem to find it. What&#039;s wrong?         </a></li><li><a href="#faq.using.shorthandbytes">           A few PHP directives may also take on shorthand byte values, as opposed      to only integer byte values.  What are all the available      shorthand byte options?  And can I use these outside of php.ini?         </a></li></ol>   <dl>    <dt><strong>     <p class="para">      I would like to write a generic PHP script that can handle data coming       from any form. How do I know which POST method variables are available?     </p>    </strong></dt>    <dd><a name="faq.using.anyform"></a>     <p class="para">      PHP offers many <a href="language.variables.predefined.html" class="link">      predefined variables</a>, like the superglobal <var class="varname">      $_POST</var>.  You may loop through <var class="varname"><a href="reserved.variables.post.html" class="classname">$_POST</a></var>      as it&#039;s an associate array of all POSTed values.  For example, let&#039;s      simply loop through it with <a href="control-structures.foreach.html" class="link">      foreach</a>, check for <a href="function.empty.html" class="function">empty()</a> values,      and print them out.      <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$empty&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$post&nbsp;</span><span style="color: #007700">=&nbsp;array();<br />foreach&nbsp;(</span><span style="color: #0000BB">$_POST&nbsp;</span><span style="color: #007700">as&nbsp;</span><span style="color: #0000BB">$varname&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">$varvalue</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(empty(</span><span style="color: #0000BB">$varvalue</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$empty</span><span style="color: #007700">[</span><span style="color: #0000BB">$varname</span><span style="color: #007700">]&nbsp;=&nbsp;</span><span style="color: #0000BB">$varvalue</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;else&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$post</span><span style="color: #007700">[</span><span style="color: #0000BB">$varname</span><span style="color: #007700">]&nbsp;=&nbsp;</span><span style="color: #0000BB">$varvalue</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /><br />print&nbsp;</span><span style="color: #DD0000">"&lt;pre&gt;"</span><span style="color: #007700">;<br />if&nbsp;(empty(</span><span style="color: #0000BB">$empty</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;print&nbsp;</span><span style="color: #DD0000">"None&nbsp;of&nbsp;the&nbsp;POSTed&nbsp;values&nbsp;are&nbsp;empty,&nbsp;posted:\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$post</span><span style="color: #007700">);<br />}&nbsp;else&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;print&nbsp;</span><span style="color: #DD0000">"We&nbsp;have&nbsp;"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">count</span><span style="color: #007700">(</span><span style="color: #0000BB">$empty</span><span style="color: #007700">)&nbsp;.&nbsp;</span><span style="color: #DD0000">"&nbsp;empty&nbsp;values\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;print&nbsp;</span><span style="color: #DD0000">"Posted:\n"</span><span style="color: #007700">;&nbsp;</span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$post</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;print&nbsp;</span><span style="color: #DD0000">"Empty:\n"</span><span style="color: #007700">;&nbsp;&nbsp;</span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$empty</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;exit;<br />}<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>      </div>     </p>          <blockquote><p><b class="note">Note</b>: <b>Superglobals: availability note</b><br />Superglobal arrays such as <var class="varname"><a href="reserved.variables.get.html" class="classname">$_GET</a></var>,<var class="varname"><a href="reserved.variables.post.html" class="classname">$_POST</a></var>, and <var class="varname"><a href="reserved.variables.server.html" class="classname">$_SERVER</a></var>, etc. are availableas of PHP 4.1.0. For more information, read the manual section on<a href="language.variables.predefined.html" class="link">superglobals</a><br /></p></blockquote>    </dd>   </dl>   <dl>    <dt><strong>     <p class="para">      I need to convert all single-quotes (&#039;) to a backslash       followed by a single-quote (\&#039;). How can I do this with a       regular expression?  I&#039;d also like to convert &quot; to \&quot; and      \ to \\.     </p>    </strong></dt>    <dd><a name="faq.using.addslashes"></a>     <p class="para">      The function <a href="function.addslashes.html" class="function">addslashes()</a> will do this.  See      also <a href="function.mysql-escape-string.html" class="function">mysql_escape_string()</a>.  You may also      strip backslashes with <a href="function.stripslashes.html" class="function">stripslashes()</a>.     </p>     <blockquote><p><b class="note">Note</b>: <b>directive note: magic_quotes_gpc</b><br />The <a href="info.configuration.html#ini.magic-quotes-gpc" class="link">magic_quotes_gpc</a>directive defaults to <i>on</i>. It essentially runs<a href="function.addslashes.html" class="function">addslashes()</a> on all GET, POST, and COOKIE data.<a href="function.stripslashes.html" class="function">stripslashes()</a> may be used to remove them.<br /></p></blockquote>    </dd>   </dl>      <dl>    <dt><strong>     <p class="para">      All my &quot; turn into \&quot; and my &#039; turn into \&#039;, how do I get rid of all       these unwanted backslashes?  How and why did they get there?     </p>    </strong></dt>    <dd><a name="faq.using.stripslashes"></a>     <p class="para">      The PHP function <a href="function.stripslashes.html" class="function">stripslashes()</a> will strip those      backslashes from your <a href="language.types.string.html" class="type string">string</a>.  Most likely the backslashes       magically exist because the PHP directive       <a href="info.configuration.html#ini.magic-quotes-gpc" class="link">magic_quotes_gpc</a> is on.     </p>          <blockquote><p><b class="note">Note</b>: <b>directive note: magic_quotes_gpc

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -