如何防止 URL 在空格处中断?没有方法有效


How do I keep a URL from breaking at the spaces? No method is working

我对此遇到了很多麻烦,$report URL 中的空格中断了,我一直在尝试解决这个问题几天了,但没有任何效果。

<form onsubmit="return validate(this)" method="post" action=
    <?
         echo "'"reports1.php?report=";
         echo rawurlencode($report);
         echo "'"";
    ?>              
>

if(isset($_GET['report'])){
        $report = $_GET['report'];
        echo "<script>alert('All reports will be appended to '"".$report."'" until GET and POST data are cleared.')</script>";
    }
    elseif($country != NULL){
        $report = $date." ".$country." ".$topic;
    }
    elseif($country == NULL){
        $report = $date." ".$region." ".$topic;
    }

这是一个例子;$report得到_GET美元

"2011-05-08",即使它应该是但它是 $_POSTING 作为"2011-05-08 巴西肉毒杆菌中毒"
"报告1.php?报告=2011-05-08 "

urlencode()就可以了。

确保将地址括在引号中,并且它位于一行上:

<form ... action="reports1.php?report=2011-05-08%20Brazil%20Botulism">

使用 PHP 的 trim() 函数删除字符串开头和结尾不需要的空格。

好吧,你不需要生它,

回声"嗨";

可以很好地与 YA 一起使用,在上面的代码中,只有一个问题,即您对表单使用 $_POST 方法而不是 $_GET

表单提交="返回验证(此)" 方法="发布"操作= 应该是

一个非常好且简单的调试代码可以帮助您检索所有 $_GETs 并将它们分配给 var,

foreach($_GET as $var=>$val)$$var=$val;

此代码将获取所有已发布的获取并将它们分配给具有自己名称的变量,($report而不是 $_GET['报告'];)您可以在所有 $_post 和 $_get 上使用此功能,以了解问题:)的确切位置。

希望对您有所帮助