>  기사  >  백엔드 개발  >  php查询字符串传值(字符串值、数字值)的例子

php查询字符串传值(字符串值、数字值)的例子

WBOY
WBOY원래의
2016-07-25 08:56:381172검색
本文介绍下,php在查询字符串中传递值的方法,举了二个例子,分别用来传递字符串值、数字值。有需要的朋友,参考下吧。

例1,在查询字符串中传递字符串值

<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>

例2,在查询字符串中传递数值

<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>


성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.