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

📄 faq.html.html

📁 php的帮助文档,涉及到PHP的案例和基本语法,以及实际应用内容
💻 HTML
📖 第 1 页 / 共 2 页
字号:
      Because <var class="varname">foo.x</var> and <var class="varname">foo.y</var> would      make invalid variable names in PHP, they are automagically converted to      <var class="varname">foo_x</var> and <var class="varname">foo_y</var>. That is, the      periods are replaced with underscores.  So, you&#039;d access these variables      like any other described within the section on retrieving       <a href="language.variables.external.html" class="link">variables from external       sources</a>.  For example, <var class="varname"><a href="reserved.variables.get.html" class="classname">$_GET['foo_x']</a></var>.      <blockquote><p><b class="note">Note</b>:                 Spaces in request variable names are converted to underscores.       <br />      </p></blockquote>     </p>    </dd>   </dl>   <dl>    <dt><strong>     <p class="para">How do I create arrays in a HTML &lt;form&gt;?</p>    </strong></dt>    <dd><a name="faq.html.arrays"></a>     <p class="para">      To get your &lt;form&gt; result sent as an       <a href="language.types.array.html" class="link">array</a> to your PHP script      you name the &lt;input&gt;, &lt;select&gt; or &lt;textarea&gt;      elements like this:      <div class="example-contents"><div class="cdata"><pre>&lt;input name=&quot;MyArray[]&quot; /&gt;&lt;input name=&quot;MyArray[]&quot; /&gt;&lt;input name=&quot;MyArray[]&quot; /&gt;&lt;input name=&quot;MyArray[]&quot; /&gt;</pre></div>      </div>      Notice the square brackets after the variable name, that&#039;s what      makes it an array. You can group the elements into different arrays      by assigning the same name to different elements:      <div class="example-contents"><div class="cdata"><pre>&lt;input name=&quot;MyArray[]&quot; /&gt;&lt;input name=&quot;MyArray[]&quot; /&gt;&lt;input name=&quot;MyOtherArray[]&quot; /&gt;&lt;input name=&quot;MyOtherArray[]&quot; /&gt;</pre></div>      </div>      This produces two arrays, MyArray and MyOtherArray, that gets sent      to the PHP script.  It&#039;s also possible to assign specific keys      to your arrays:      <div class="example-contents"><div class="cdata"><pre>&lt;input name=&quot;AnotherArray[]&quot; /&gt;&lt;input name=&quot;AnotherArray[]&quot; /&gt;&lt;input name=&quot;AnotherArray[email]&quot; /&gt;&lt;input name=&quot;AnotherArray[phone]&quot; /&gt;</pre></div>      </div>      The AnotherArray array will now contain the keys 0, 1, email and phone.      </p>      <p class="para">       <blockquote><p><b class="note">Note</b>:                  Specifying an arrays key is optional in HTML.  If you do not specify         the keys, the array gets filled in the order the elements appear in         the form.  Our first example will contain keys 0, 1, 2 and 3.        <br />       </p></blockquote>      </p>      <p class="para">      See also      <a href="ref.array.html" class="link">Array Functions</a> and      <a href="language.variables.external.html" class="link">Variables From External      Sources</a>.     </p>    </dd>   </dl>   <dl>    <dt><strong>     <p class="para">      How do I get all the results from a select multiple HTML tag?     </p>    </strong></dt>    <dd><a name="faq.html.select-multiple"></a>     <p class="para">      The select multiple tag in an HTML construct allows users to      select multiple items from a list. These items are then passed      to the action handler for the form. The problem is that they      are all passed with the same widget name. I.e.      <div class="example-contents"><div class="cdata"><pre>&lt;select name=&quot;var&quot; multiple=&quot;yes&quot;&gt;</pre></div>      </div>      Each selected option will arrive at the action handler as:      <div class="example-contents"><div class="cdata"><pre>var=option1var=option2var=option3      </pre></div></div>      Each option will overwrite the contents of the previous      <var class="varname">$var</var> variable. The solution is to use      PHP&#039;s &quot;array from form element&quot; feature. The following      should be used:      <div class="example-contents"><div class="cdata"><pre>&lt;select name=&quot;var[]&quot; multiple=&quot;yes&quot;&gt;</pre></div>      </div>      This tells PHP to treat <var class="varname">$var</var> as an array and      each assignment of a value to var[] adds an item to the array.      The first item becomes <var class="varname">$var[0]</var>, the next      <var class="varname">$var[1]</var>, etc. The <a href="function.count.html" class="function">count()</a>      function can be used to determine how many options were selected,      and the <a href="function.sort.html" class="function">sort()</a> function can be used to sort      the option array if necessary.     </p>     <p class="para">      Note that if you are using JavaScript the <i>[]</i>      on the element name might cause you problems when you try to      refer to the element by name. Use it&#039;s numerical form element      ID instead, or enclose the variable name in single quotes and      use that as the index to the elements array, for example:      <div class="example-contents"><div class="cdata"><pre>variable = documents.forms[0].elements[&#039;var[]&#039;];      </pre></div></div>     </p>    </dd>   </dl>   <dl>    <dt><strong>     <p class="para">      How can I pass a variable from Javascript to PHP?     </p>    </strong></dt>    <dd><a name="faq.html.javascript-variable"></a>     <p class="para">      Since Javascript is (usually) a client-side technology, and      PHP is (usually) a server-side technology, and since HTTP is a      &quot;stateless&quot; protocol, the two languages cannot directly share      variables.     </p>     <p class="para">      It is, however, possible to pass variables between the two.      One way of accomplishing this is to generate Javascript code      with PHP, and have the browser refresh itself, passing specific      variables back to the PHP script. The example below shows      precisely how to do this -- it allows PHP code to capture screen      height and width, something that is normally only possible on      the client side.     </p>     <p class="para">      <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;(isset(</span><span style="color: #0000BB">$_GET</span><span style="color: #007700">[</span><span style="color: #DD0000">'width'</span><span style="color: #007700">])&nbsp;AND&nbsp;isset(</span><span style="color: #0000BB">$_GET</span><span style="color: #007700">[</span><span style="color: #DD0000">'height'</span><span style="color: #007700">]))&nbsp;{<br />&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;output&nbsp;the&nbsp;geometry&nbsp;variables<br />&nbsp;&nbsp;</span><span style="color: #007700">echo&nbsp;</span><span style="color: #DD0000">"Screen&nbsp;width&nbsp;is:&nbsp;"</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">$_GET</span><span style="color: #007700">[</span><span style="color: #DD0000">'width'</span><span style="color: #007700">]&nbsp;.</span><span style="color: #DD0000">"&lt;br&nbsp;/&gt;\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"Screen&nbsp;height&nbsp;is:&nbsp;"</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">$_GET</span><span style="color: #007700">[</span><span style="color: #DD0000">'height'</span><span style="color: #007700">]&nbsp;.</span><span style="color: #DD0000">"&lt;br&nbsp;/&gt;\n"</span><span style="color: #007700">;<br />}&nbsp;else&nbsp;{<br />&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;pass&nbsp;the&nbsp;geometry&nbsp;variables<br />&nbsp;&nbsp;//&nbsp;(preserve&nbsp;the&nbsp;original&nbsp;query&nbsp;string<br />&nbsp;&nbsp;//&nbsp;&nbsp;&nbsp;--&nbsp;post&nbsp;variables&nbsp;will&nbsp;need&nbsp;to&nbsp;handled&nbsp;differently)<br /><br />&nbsp;&nbsp;</span><span style="color: #007700">echo&nbsp;</span><span style="color: #DD0000">"&lt;script&nbsp;language='javascript'&gt;\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"&nbsp;&nbsp;location.href=\"${_SERVER['SCRIPT_NAME']}?${_SERVER['QUERY_STRING']}"<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #DD0000">"&amp;width=\"&nbsp;+&nbsp;screen.width&nbsp;+&nbsp;\"&amp;height=\"&nbsp;+&nbsp;screen.height;\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"&lt;/script&gt;\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;exit();<br />}<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>      </div>     </p>    </dd>   </dl>  </div> </div><hr /><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="faq.using.html">Using PHP</a></div> <div class="next" style="text-align: right; float: right;"><a href="faq.com.html">PHP and COM</a></div> <div class="up"><a href="faq.html">FAQ</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div></body></html>

⌨️ 快捷键说明

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