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

📄 faq.html.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>PHP and HTML</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.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><hr /><div>  <h1>PHP and HTML</h1>    <p class="para">   PHP and HTML interact a lot: PHP can generate HTML, and HTML   can pass information to PHP.  Before reading these faqs, it&#039;s   important you learn how to retrieve <a href="language.variables.external.html" class="link">   variables from external sources</a>.  The manual page on   this topic includes many examples as well.  Pay close attention to   what <i>register_globals</i> means to you too.  </p>  <div class="qandaset"><ol class="qandaset_questions"><li><a href="#faq.html.encoding">           What encoding/decoding do I need when I pass a value through a form/URL?         </a></li><li><a href="#faq.html.form-image">           I&#039;m trying to use an &lt;input type=&quot;image&quot;&gt; tag, but       the $foo.x and $foo.y variables      aren&#039;t available.  $_GET['foo.x'] isn&#039;t existing      either.  Where are they?           </a></li><li><a href="#faq.html.arrays">     How do I create arrays in a HTML &lt;form&gt;?    </a></li><li><a href="#faq.html.select-multiple">           How do I get all the results from a select multiple HTML tag?         </a></li><li><a href="#faq.html.javascript-variable">           How can I pass a variable from Javascript to PHP?         </a></li></ol>   <dl>    <dt><strong>     <p class="para">      What encoding/decoding do I need when I pass a value through a form/URL?     </p>    </strong></dt>    <dd><a name="faq.html.encoding"></a>     <p class="para">      There are several stages for which encoding is important. Assuming that      you have a <a href="language.types.string.html" class="type string">string</a> <var class="varname">$data</var>, which contains      the string you want to pass on in a non-encoded way, these are the      relevant stages:      <ul class="itemizedlist">       <li class="listitem">        <p class="para">         HTML interpretation. In order to specify a random string, you         <em class="emphasis">must</em> include it in double quotes, and          <a href="function.htmlspecialchars.html" class="function">htmlspecialchars()</a> the whole value.        </p>       </li>       <li class="listitem">        <p class="para">         URL: A URL consists of several parts. If you want your data to be         interpreted as one item, you <em class="emphasis">must</em> encode it with         <a href="function.urlencode.html" class="function">urlencode()</a>.        </p>       </li>      </ul>     </p>     <p class="para">      <div class="example">       <p><b>Example #1 A hidden HTML form element</b></p>        <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">echo&nbsp;</span><span style="color: #DD0000">"&lt;input&nbsp;type='hidden'&nbsp;value='"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">htmlspecialchars</span><span style="color: #007700">(</span><span style="color: #0000BB">$data</span><span style="color: #007700">)&nbsp;.&nbsp;</span><span style="color: #DD0000">"'&nbsp;/&gt;\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>        </div>      </div>      <blockquote><p><b class="note">Note</b>:        <span class="simpara">        It is wrong to <a href="function.urlencode.html" class="function">urlencode()</a>        <var class="varname">$data</var>, because it&#039;s the browsers responsibility to        <a href="function.urlencode.html" class="function">urlencode()</a> the data. All popular browsers do that        correctly. Note that this will happen regardless of the method (i.e.,        GET or POST). You&#039;ll only notice this in case of GET request though,        because POST requests are usually hidden.       </span>      </p></blockquote>      <div class="example">       <p><b>Example #2 Data to be edited by the user</b></p>        <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">echo&nbsp;</span><span style="color: #DD0000">"&lt;textarea&nbsp;name='mydata'&gt;\n"</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">$data</span><span style="color: #007700">).</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"&lt;/textarea&gt;"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>        </div>      </div>      <blockquote><p><b class="note">Note</b>:        <span class="simpara">        The data is shown in the browser as intended, because the browser will        interpret the HTML escaped symbols.       </span>       <span class="simpara">        Upon submitting, either via GET or POST, the data will be urlencoded        by the browser for transferring, and directly urldecoded by PHP. So in        the end, you don&#039;t need to do any urlencoding/urldecoding yourself,        everything is handled automagically.       </span>      </p></blockquote>      <div class="example">       <p><b>Example #3 In a URL</b></p>        <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">echo&nbsp;</span><span style="color: #DD0000">"&lt;a&nbsp;href='"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">htmlspecialchars</span><span style="color: #007700">(</span><span style="color: #DD0000">"/nextpage.php?stage=23&amp;data="&nbsp;</span><span style="color: #007700">.<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">urlencode</span><span style="color: #007700">(</span><span style="color: #0000BB">$data</span><span style="color: #007700">))&nbsp;.&nbsp;</span><span style="color: #DD0000">"'&gt;\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>        </div>      </div>      <blockquote><p><b class="note">Note</b>:        <span class="simpara">        In fact you are faking a HTML GET request, therefore it&#039;s necessary to        manually <a href="function.urlencode.html" class="function">urlencode()</a> the data.       </span>      </p></blockquote>      <blockquote><p><b class="note">Note</b>:        <span class="simpara">        You need to <a href="function.htmlspecialchars.html" class="function">htmlspecialchars()</a> the whole URL, because the        URL occurs as value of an HTML-attribute. In this case, the browser        will first un-<a href="function.htmlspecialchars.html" class="function">htmlspecialchars()</a> the value, and then pass        the URL on. PHP will understand the URL correctly, because you        <b>urlencoded()</b> the data.       </span>       <span class="simpara">        You&#039;ll notice that the <i>&amp;</i> in the URL is replaced        by <i>&amp;amp;</i>. Although most browsers will recover        if you forget this, this isn&#039;t always possible. So even if your URL is        not dynamic, you <em class="emphasis">need</em> to        <a href="function.htmlspecialchars.html" class="function">htmlspecialchars()</a> the URL.       </span>      </p></blockquote>     </p>         </dd>   </dl>   <dl>    <dt><strong>     <p class="para">      I&#039;m trying to use an &lt;input type=&quot;image&quot;&gt; tag, but       the <var class="varname">$foo.x</var> and <var class="varname">$foo.y</var> variables      aren&#039;t available.  <var class="varname"><a href="reserved.variables.get.html" class="classname">$_GET['foo.x']</a></var> isn&#039;t existing      either.  Where are they?       </p>    </strong></dt>    <dd><a name="faq.html.form-image"></a>     <p class="para">      When submitting a form, it is possible to use an image instead of      the standard submit button with a tag like:      <div class="example-contents"><div class="cdata"><pre>&lt;input type=&quot;image&quot; src=&quot;image.gif&quot; name=&quot;foo&quot; /&gt;</pre></div>      </div>      When the user clicks somewhere on the image, the accompanying form      will be transmitted to the server with two additional variables:      <var class="varname">foo.x</var> and <var class="varname">foo.y</var>.     </p>     <p class="para">

⌨️ 快捷键说明

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