开发者

Validate a query string?

开发者_JAVA百科first=value
first=value&arr[]=foo+bar&arr[]=baz

How can I use PHP to validate a query string, which is a sequence of

[name]=[value]&


I can't say I understand what you are asking, but if we are talking about the specific value above:

$value = $_GET['first']; //value
$arr = isset($_GET['arr']) ? $_GET['arr'] : null; //array('foo bar', 'baz')

If you are asking if you can validate whether a query string is in a usable format .. well you can't, really. There is large variety of possible query strings and you can really put in whatever you want. It is up to you to check if the values you are expecting are set and checking whether the data in them is usable for your purposes.


<?php
if (isset($_GET['name'])) {
        $name = $_GET['name'];
        if ($name == 'value') {...};
}
if (!isset($_GET['arr'])) {
      echo "URL is not in correct format!";
      exit;
}
?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜