Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/286.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 比较url和字符串_Php - Fatal编程技术网

Php 比较url和字符串

Php 比较url和字符串,php,Php,如何比较PHP中的服务器请求和字符串 我已经好几年没有做过任何网络开发了,完全忘记了 <?php $min = 0; $max = 9; $index = 0; $pages = 2; for($i = 1; $i <= $pages; $i++){ if( $_SERVER['REQUEST_URI'] == '/index.php?id='.(string)$i ){ $in

如何比较PHP中的服务器请求和字符串

我已经好几年没有做过任何网络开发了,完全忘记了

<?php
        $min = 0; $max = 9;
        $index = 0; $pages = 2;

        for($i = 1; $i <= $pages; $i++){
            if( $_SERVER['REQUEST_URI'] == '/index.php?id='.(string)$i ){
                $index = $i - 1;
                $min = $i * 9;
                $max = 2 * $min;
            }
        }
?>

如果您只是尝试比较URI参数,可以这样做:

$min = 0; $max = 9;
$index = 0; $pages = 2;
for ($i = 1; $i <= $pages; $i++) {
    if ($_GET['id'] == $i) {
        $index = $i - 1;
        $min = $i * 9;
        $max = 2 * $min;
    }
}

$\u-GET和$\u-POST允许您通过$\u-GET['id']、$\u-GET['id2']和$\u-GET['name']访问id=10&id2=100&name=aust等参数。

如果您试图找出id等于什么,请使用$\u-GET['id']

另一种选择:

switch ($_GET['id']) {
    case 1:
        print "one";
        break;
    case default:
        print "invalid";
        break;
}

在PHP中,您的请求将出现在$\u-GET或$\u-POST或$\u-request中,如果您希望任何一种方式

对我来说都不错,什么不起作用?当我转到/index.PHP?id=1时,我的if语句没有执行如果您试图找出id等于什么,请使用$\u-GET['id']URL,对吗?不是URL最好对字符串$\u GET['id']='0'进行严格比较,因为'php'==0=>true。看见
switch ($_GET['id']) {
    case 1:
        print "one";
        break;
    case default:
        print "invalid";
        break;
}