English 中文(简体)
如何获取和排除 appended带入ur的 que子? PHP
原标题:How to get and disect the query string appended into a url? PHP
  • 时间:2010-06-03 10:50:42
  •  标签:
  • php

我正试图开发一个PHP级,使我能够把 que带入ur子,并根据变数处理。 如何做到这一点?

iii

www.example.com?var1=a&var2=b&var3=c

现在,我想获得<代码>?var1=a&var2=b&var3=c部分,并根据变量处理。

感谢您的答复

但是,我希望能找到一个办法,使我能够找到整个问题,因为我确信,将向卢爱阵寄出的变数,因此,_GET方法赢得了适当的工作。

增 编

最佳回答

如果你想要获得URL参数,作为你可以使用的手段:

$_SERVER[ QUERY_STRING ]

但是,我不敢肯定这比<代码>_GET更有用。 你说:

我获得可变名称的保证

可通过<代码>_GET阵列填foreach。 住宿:

foreach ($_GET as $key => $val) {
    echo $key . ": " . $val;
}

但是,如果你重新谈论任意 URL(不一定是要求采用的方法),因此上述方法赢得了t工作,因为它们显然在美元上获得了t。 相反,你可以使用<>。

$url =  http://username:password@hostname/path?arg=value#anchor ;

print_r(parse_url($url));

echo parse_url($url, PHP_URL_QUERY);

产出:

Array
(
    [scheme] => http
    [host] => hostname
    [user] => username
    [pass] => password
    [path] => /path
    [query] => arg=value
    [fragment] => anchor
)
arg=value
问题回答

http://www.w3schools.com/php/php_get.asp”rel=“nofollow noreferer”_$_GET

这里是一小类。 它应当发挥作用,但并未经过测试。

<?php
class URLHandler 
{
    public $get;

    public function __construct( $get );
    {
        $this->get = $get;
    }

    public function get_var( $var )
    {
        return htmlspecialchars( $this->get[$var] );
    }

    public function check_var( $var, $is )
    {
        if( $this->get_var( $var ) == $is )
        {
            return true;
        }
        else
        {
            return false;
        }
    }
}

// Below is how you can use this class
$URL = new URLHandler( $_GET );
if( $URL->check_var(  var1 ,  a  ) )
{
    echo  yes your first var is a ;
    // Here you can add a function or functions which should be loaded if var1 = a
}
else
{
    echo  No, your first var is not a, its  .$URL->get_var(  var2  );
    // Here you can add a function or functions which should be loaded if var1 is not a
}

if( $URL->check_var(  var2 ,  a  ) )
{
    echo  and your second var is a ;
}
else
{
    echo  your second var is not a, its  .$URL->get_var(  var2  );
}
?>




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签