Home > Backend Development > PHP Tutorial > Example of PHP query string passing value (string value, numeric value)

Example of PHP query string passing value (string value, numeric value)

WBOY
Release: 2016-07-25 08:56:38
Original
1237 people have browsed it
This article introduces the method of PHP passing values ​​in query strings, and gives two examples, which are used to pass string values ​​and numeric values ​​respectively. Friends in need, please refer to it.

Example 1, passing string value in query string

<html>
<body>
  <div align="center">
    <p>Click a link to move to a new page:</p>
    Content 1<br />
    Content 2<br />
    Content 3<br />
    <?php
      $page = trim (urldecode (stripslashes ($_GET['page'])));
      if (isset ($page) && $page != ""){
        if (is_file ($page)){
          require_once ($page);
        } else {
          echo "<p>很抱歉,您请求的页面不存在。</p>";
        }
      }
    ?>
  </div>
</body>
</html>
Copy after login

Example 2, passing numerical value in query string

<html>
<head>
<title>查询字符串传递数值-bbs.it-home.org</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
  <div align="center">
    <p>Click a link to change the text color of the verbiage below:</p>
    Green<br />
    Red<br />
    Blue<br />
    重置信息
    <?php
      if (isset ($_GET['color'])){
        $color = intval ($_GET['color']);
      } else {
        $color = "";
      }
      if ($color == 1){
        $fontcolor = "00FF00";
      } elseif ($color == 2){
        $fontcolor = "FF0000";
      } elseif ($color == 3){
        $fontcolor = "0000FF";
      } else {
        $fontcolor = "000000";
      }
      ?><p style="color: #<?php echo $fontcolor; ?>; font-weight: bold;">欢迎访问程序员之家网站!</p><?php
    ?>
  </div>
</body>
</html>
Copy after login


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template