0

Im running a website for a client which is accessed when a get string is passed to it, I just received their new link, and there are 5 things I need to pull from the link. one of the items is an ID, so the get string would look like this normally:

www.website.com/index.php?id=1232352346

which is how it was being sent before, however this newest one has it set up like this:

www.website.com/index.php?id=2345134&123461

what Im wondering is if I pull that id in like so

$id=htmlspecialchars($_GET["id"], ENT_QUOTES);

will it have just the number before the second & (ex: 2345134) or will it have the entire thing (ex: 2345134&123461)?

4

5 に答える 5

2

それらをバラバラにしたい場合は、このクイックフィックスを試すことができます

array_walk($_GET, function(&$i,$k){empty($i) AND $i=$k;});
var_dump($_GET);

出力

array
  'id' => string '2345134' (length=7)
  123461 => int 123461

文字列全体が必要id、URL の唯一のキーである場合は、試すことができます

list($key, $value) = explode("=", $_SERVER['QUERY_STRING']);
var_dump($key,$value);

出力

string 'id' (length=2)
string '2345134&123461' (length=14)
于 2012-10-29T17:42:00.987 に答える
2

を URL エンコードしていない場合、&処理方法に関係なく、ID の後半は別のパラメーターとして扱われます。$_GET

それを解析するにはいくつかの方法があります。単純な方法の 1 つは、空のパラメーターをチェックし、それが ID の残りの半分であると想定することです。クエリ文字列がどのように解析されるかを無視して、自分で解析することもできます (おそらく、&2 桁の内部にあるものはすべて無視します)。

しかし、実際には、URL が適切にエンコードされていることを確認するのが最善の方法です。そうすれば、すべてが期待どおりに機能します。

指定した URL がどのように解析されるかを次に示します ( を使用して、入力parse_str()方法と一致する必要があります$_GET)。

配列(2) {
  ["id"]=>
  文字列(7) "2345134"
  [123461]=>
  文字列(0) ""
}

この正しい形式の URL は次のように解析されます。

/index.php?id=1234%265678

配列(1) {
  ["id"]=>
  文字列(9) "1234&5678"
}

クライアントが PHP を使用して URL を生成している場合は、PHP を使用できhttp_build_query()、すべてのエンコーディングが自動的に処理されます。

于 2012-10-29T17:45:37.890 に答える
1
$url = "www.website.com/index.php?id=2345134&123461";
$parsed = parse_url($url);
parse_str($parsed["query"], $query);
var_dump($query);

parse_url無効なURLの場合は失敗することに注意してください。


これは機能するはずです:

$id = $_GET["id"];
unset($_GET["id");
$keys = array_keys($_GET);
unset($keys);
$other = $_GET[$keys[0]];
var_dump($id, $other);
于 2012-10-29T17:38:48.843 に答える
1

試す

$url = "2345134&123461";
$pieces = explode("&", $url);
echo $pieces[0]; // piece1
echo $pieces[1]; // piece2
 var_dump($pieces );

コードパッド

于 2012-10-29T17:40:06.797 に答える
0

どうですか.. www.website.com/index.php?id=2345134&123461

//explode it
        $string=$_GET['id'];
        list($first,$second)=explode('&',$string);
//$first = 2345134
//$second = 123461

聖なるベジェサスの答えはすぐに来ます..

于 2012-10-29T17:47:21.247 に答える