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

📄 language.variables.external.html

📁 php的帮助文档,涉及到PHP的案例和基本语法,以及实际应用内容
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head>  <title>Variables From External Sources</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="language.variables.html">Variables</a></div> <div class="next" style="text-align: right; float: right;"><a href="language.constants.html">Constants</a></div> <div class="up"><a href="language.variables.html">Variables</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div><hr /><div id="language.variables.external" class="sect1">   <h2 class="title">Variables From External Sources</h2>      <div id="language.variables.external.form" class="sect2">    <h3 class="title">HTML Forms (GET and POST)</h3>    <p class="simpara">     When a form is submitted to a PHP script, the information from      that form is automatically made available to the script.  There      are many ways to access this information, for example:    </p>    <p class="para">     <div class="example">      <p><b>Example #1 A simple HTML form</b></p>      <div class="example-contents"><div class="cdata"><pre>&lt;form action=&quot;foo.php&quot; method=&quot;post&quot;&gt;    Name:  &lt;input type=&quot;text&quot; name=&quot;username&quot; /&gt;&lt;br /&gt;    Email: &lt;input type=&quot;text&quot; name=&quot;email&quot; /&gt;&lt;br /&gt;    &lt;input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;Submit me!&quot; /&gt;&lt;/form&gt;</pre></div>      </div>     </div>    </p>    <p class="para">     Depending on your particular setup and personal preferences, there      are many ways to access data from your HTML forms.  Some examples are:    </p>        <p class="para">     <div class="example">      <p><b>Example #2 Accessing data from a simple POST HTML form</b></p>      <div class="example-contents"><div class="cdata"><pre>&lt;?php // Available since PHP 4.1.0   echo $_POST[&#039;username&#039;];   echo $_REQUEST[&#039;username&#039;];   import_request_variables(&#039;p&#039;, &#039;p_&#039;);   echo $p_username;// Unavailable since PHP 6. As of PHP 5.0.0, these long predefined// variables can be disabled with the register_long_arrays directive.   echo $HTTP_POST_VARS[&#039;username&#039;];// Available if the PHP directive register_globals = on. As of // PHP 4.2.0 the default value of register_globals = off.// Using/relying on this method is not preferred.   echo $username;?&gt;</pre></div>      </div>     </div>    </p>    <p class="para">     Using a GET form is similar except you&#039;ll use the appropriate     GET predefined variable instead.  GET also applies to the     QUERY_STRING (the information after the &#039;?&#039; in a URL).  So,     for example, <i>http://www.example.com/test.php?id=3</i>     contains GET data which is accessible with <var class="varname"><a href="reserved.variables.get.html" class="classname">$_GET['id']</a></var>.     See also <var class="varname"><a href="reserved.variables.request.html" class="classname">$_REQUEST</a></var> and      <a href="function.import-request-variables.html" class="function">import_request_variables()</a>.    </p>    <blockquote><p><b class="note">Note</b>:            <a href="language.variables.superglobals.html" class="link">Superglobal arrays</a>,       like <var class="varname"><a href="reserved.variables.post.html" class="classname">$_POST</a></var> and <var class="varname"><a href="reserved.variables.get.html" class="classname">$_GET</a></var>, became       available in PHP 4.1.0     <br />    </p></blockquote>    <p class="para">     As shown, before PHP 4.2.0 the default value for <a href="ini.core.html#ini.register-globals" class="link">register_globals</a>     was <em class="emphasis">on</em>.  The PHP      community is encouraging all to not rely on this directive      as it&#039;s preferred to assume it&#039;s <em class="emphasis">off</em> and code      accordingly.    </p>    <blockquote><p><b class="note">Note</b>:            The <a href="info.configuration.html#ini.magic-quotes-gpc" class="link">magic_quotes_gpc</a>       configuration directive affects Get, Post and Cookie values.  If       turned on, value (It&#039;s &quot;PHP!&quot;) will automagically become (It\&#039;s \&quot;PHP!\&quot;).      Escaping is needed for DB insertion.  See also       <a href="function.addslashes.html" class="function">addslashes()</a>, <a href="function.stripslashes.html" class="function">stripslashes()</a> and       <a href="sybase.configuration.html#ini.magic-quotes-sybase" class="link">magic_quotes_sybase</a>.     <br />    </p></blockquote>        <p class="simpara">     PHP also understands arrays in the context of form variables      (see the <a href="faq.html.html" class="link">related faq</a>).  You may,      for example, group related variables together, or use this      feature to retrieve values from a multiple select input.  For      example, let&#039;s post a form to itself and upon submission display      the data:    </p>    <p class="para">     <div class="example">      <p><b>Example #3 More complex form variables</b></p>      <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">if&nbsp;(</span><span style="color: #0000BB">$_POST</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'&lt;pre&gt;'</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #0000BB">htmlspecialchars</span><span style="color: #007700">(</span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$_POST</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">true</span><span style="color: #007700">));<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'&lt;/pre&gt;'</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;<br /></span>&lt;form&nbsp;action=""&nbsp;method="post"&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;Name:&nbsp;&nbsp;&lt;input&nbsp;type="text"&nbsp;name="personal[name]"&nbsp;/&gt;&lt;br&nbsp;/&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;Email:&nbsp;&lt;input&nbsp;type="text"&nbsp;name="personal[email]"&nbsp;/&gt;&lt;br&nbsp;/&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;Beer:&nbsp;&lt;br&nbsp;/&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;select&nbsp;multiple&nbsp;name="beer[]"&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;option&nbsp;value="warthog"&gt;Warthog&lt;/option&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;option&nbsp;value="guinness"&gt;Guinness&lt;/option&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;option&nbsp;value="stuttgarter"&gt;Stuttgarter&nbsp;Schwabenbr盲u&lt;/option&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;/select&gt;&lt;br&nbsp;/&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;input&nbsp;type="submit"&nbsp;value="submit&nbsp;me!"&nbsp;/&gt;<br />&lt;/form&gt;</span></code></div>      </div>     </div>    </p>    <div id="language.variables.external.form.submit" class="sect3">     <h4 class="title">IMAGE SUBMIT variable names</h4>     <p class="simpara">      When submitting a form, it is possible to use an image instead      of the standard submit button with a tag like:

⌨️ 快捷键说明

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