Jquery中文网 www.jquerycn.cn
Jquery中文网 >  脚本编程  >  php  >  正文 php查询字符串传值(字符串值、数字值)的例子

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

发布时间:2016-12-12   编辑:www.jquerycn.cn
本文介绍下,php在查询字符串中传递值的方法,举了二个例子,分别用来传递字符串值、数字值。有需要的朋友,参考下吧。

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

<html>
<body>
  <div align="center">
    <p>Click a link to move to a new page:</p>
    <a href="index.php?page=content1.html">Content 1</a><br />
    <a href="index.php?page=content2.html">Content 2</a><br />
    <a href="index.php?page=content3.html">Content 3</a><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>查询字符串传递数值-www.jbxue.com</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>
    <a href="index.php?color=1">Green</a><br />
    <a href="index.php?color=2">Red</a><br />
    <a href="index.php?color=3">Blue</a><br />
    <a href="index.php">重置信息</a>
    <?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>

您可能感兴趣的文章:
PHP字符串函数与使用分析
php字符串查找 查找字符最后一次出现位置
php 字符串函数教程与实例代码
php查询字符串传值(字符串值、数字值)的例子
php5 字符串处理函数汇总
php字符串查找函数(strrpos与strchr)
如何使用PHP中的字符串函数
php字符串函数有哪些
php查找指定字符串并删除
url链接中特殊字符转义方法

[关闭]