我正试图开发一个PHP级,使我能够把 que带入ur子,并根据变数处理。 如何做到这一点?
iii
www.example.com?var1=a&var2=b&var3=c
现在,我想获得<代码>?var1=a&var2=b&var3=c部分,并根据变量处理。
感谢您的答复
但是,我希望能找到一个办法,使我能够找到整个问题,因为我确信,将向卢爱阵寄出的变数,因此,_GET方法赢得了适当的工作。
增 编
我正试图开发一个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 = 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
// Current URL: www.example.com?var1=a&var2=b&var3=c
function handleUrl()
{
$var1 = $_GET[ var1 ]; // now contains a
$var2 = $_GET[ var2 ]; // now contains b
$var3 = $_GET[ var3 ]; // now contains c
return "Querystring now contains $var1 $var2 and $var3";
}
More information at http://php.net/manual/en/reserved.variables.get.php
如果您的参数储存在一个变量中,则使用http://php.net/manual/en/Function.parse-str.php” rel=“nofollow noreferer”>parse_str
。 例:
$str = var1=a&var2=b&var3=c ;
parse_str($str);
echo $var1;
这里是一小类。 它应当发挥作用,但并未经过测试。
<?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 );
}
?>
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 ...
<?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 = ...
I found this script online that creates a thumbnail out of a image but the thumbnail image is created with poor quality how can I improve the quality of the image. And is there a better way to create ...
如何确认来自正确来源的数字。
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 ...
I wonder there is a way to post a message to a facebook business page with cURL? thanks
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? 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 ...