
198
|
第
8
章
Web
技术
<body>
<?php $fahrenheit = $_GET['fahrenheit']; ?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="GET">
Fahrenheit temperature:
<input type="text" name="fahrenheit" value="<?php echo $fahrenheit; ?>" /><br />
<input type="submit" value="Convert to Celsius!" />
</form>
<?php if (!is_null($fahrenheit)) {
$celsius = ($fahrenheit - 32) * 5 / 9;
printf("%.2fF is %.2fC", $fahrenheit, $celsius);
} ?>
</body>
</html>
多值参数
用
select
标签创建的
HTML
选择列表允许有多个选项。要确保
PHP
能识别浏览器传递
的多值,你需要在
HTML
表单中使用中括号
[]
结尾,例如
:
<select name="languages[]">
<option name="c">C</option>
<option name="c++">C++</option>
<option name="php">PHP</option>
<option name="perl">Perl</option> ...