2012-07-19 60 views
1

我为我的生活无法弄清这一点......从php url字符串中删除中断?

我有一个表单,它最终将查询字符串传递一些字段。

$f = $_GET['full']; 
$t = $_GET['title']; 

$illegal = array("'", "#039;"); 
$f = str_replace($illegal, "", $f); 
$t = str_replace($illegal, "", $t); 

出于某种奇怪的原因,省略号那里搞乱我需要什么,所以我删除他们,因为他们是(对于第一次出现和#039 ';之后)转动起来。

现在$ t输出一个可用的字符串。 $ f但可以包含休息。而他们最终的字符串作为

<br+%2F> 

我已经试过

$f = preg_replace("/\r?\n/", "", $f); 

$breaks = array("<br+%2F>", "/\r?\n/", "<br />"); 
$f = str_replace($breaks, "%20", $f); 

,但是当我将它输出在URL我仍然得到

http://www.domain.com?t=good%20string&f=bad<br+%2F>string 

正在导致404页未找到错误。 :(

编辑

$f = html_entity_decode($_GET['full']); 
$t = html_entity_decode($_GET['title']); 

$illegal = array("&#039;", "#039;"); 
$f = str_replace($illegal, "", $f); 
$t = str_replace($illegal, "", $t); 

$f = htmlspecialchars($f); 

$breaks = array("<br+%2F>%0D%0A<br+%2F>%0D%0A", "<br+%2F>%0D%0A"); 
$f = str_replace($breaks, "%20", $f); 

if (---private-stuff---) { 
header('Location: /?title=' . $t . '&full=' . $f . '&fifth=fith%20percent'); 
} 

最后$ F仍然包含

<br+%2F>%0D%0A<br+%2F>%0D%0A 
在url

,不应该对这些功能ONE剥离出来?!?

+0

404代表URL地址无效。意思是你应该试试'http://www.domain.com/index.php?...' – 2012-07-19 00:34:57

+0

我明白404是什么 - 但是http://www.domain.com?t=good%20string&f=bad 字符串给出了404。如果我删除了,它工作得很好。 – Xhynk 2012-07-19 00:37:56

回答

4

使用html entities decode

$string = html_entity_decode("&#039;"); 
echo $string ; // ' 

所以你的情况,这将是

$f = html_entity_decode($_GET['full']); 
$t = html_entity_decode($_GET['title']); 
0

既然你得到一个404,这可能是因为你有一个的.htaccess规则(ModRewrite)正试图路线,你到其他页面(即不不存在)。听起来像是你可能有两个不同的问题...

为了让您的实际文本背出查询字符串,伊布是正确的......使用html_entity_decode()

+0

我不知道我明白。如果我提交表单,它工作得很好,我会重定向到正确的页面。如果我提交表格,但在