如何在 php 中获取 $_get['a'] 中的 url 数据



我正在将我的url和值从javascript传递到PHP,比如:

<script>
var a= "10-test(8 2) DVI-A Male";
var b= "8-test(6 2) DVI-A Male";
var test = a.replace("+", "%2B"); 
var test1 = b.replace("+", "%2B"); 
window.open("listing.php?cond=true" + "&a=" + (test.replaceAll("%", " ")) + "&b=" + test1.replaceAll("%", " "));
</script>

我有一个类似的URL

localhost://listing.php?cond=true&a=10-test%20(8+2)%20DVI-A%20Male&b=test2%20Male

我想得到一个&b为此,我使用了:

<?php
$a = $_GET["a"];
$b = $_GET["b"]; ?>

但我得到了像一样的结果

$a = 10-test(8 2) DVI-A Male

我在结果中丢失了+符号。我如何才能得到这样的结果:

10-test(8+2) DVI-A Male

+符号表示URL中的一个空格。需要将其编码为%2B

localhost://listing.php?cond=true&a=10-test%20(8%2B2)%20DVI-A%20Male&b=test2%20Male

应该返回$_GET数组,如:

array(
'cond' => 'true',
'a' => '10-test (8+2) DVI-A Male',
'b' => 'test2 Male',
)

最新更新