Php nl2br或str_替换不适用于$_GET变量

Php nl2br或str_替换不适用于$_GET变量,php,get,str-replace,nl2br,Php,Get,Str Replace,Nl2br,我搜索了又搜索,但似乎只有我有这个问题。所以我想从这个$\u GET变量转换换行符。 这是我的网址: test.php?name=Line%201\nLine%202\rLine%203\r\nLine%204 在我的代码中,我尝试过: print nl2br($_GET['name']); //doesn't work 我也尝试过: print str_replace(array("\r\n", "\r", "\n"), "<br>", $name); //doesn't wo

我搜索了又搜索,但似乎只有我有这个问题。所以我想从这个$\u GET变量转换换行符。 这是我的网址:

test.php?name=Line%201\nLine%202\rLine%203\r\nLine%204
在我的代码中,我尝试过:

print nl2br($_GET['name']); //doesn't work
我也尝试过:

print str_replace(array("\r\n", "\r", "\n"), "<br>", $name); //doesn't work
print str\u replace(数组(“\r\n”、“\r”、“\n”)、“
”、$name)//不起作用
每次打印出原始字符串(第1行\n第2行\r第3行\r\n第4行\n)时,不做任何更改。 但是,如果我尝试使用一个未传入的变量,它总是有效的。例如:

$other = "Line 1\nLine 2\rLine 3\r\nLine 4\n";
print `nl2br($_GET['name']);
print str_replace(array("\r\n", "\r", "\n"), "<br>", $other);
$other=“第1行\nLine 2\rLine 3\r\nLine 4\n”;
打印'nl2br($_GET['name']);
打印str\u replace(数组(“\r\n”,“\r”,“\n”),“
”,$other);

我还尝试在一个全新的文档中这样做,我没有任何“消毒”脚本,或者任何其他脚本仍然无法绕过它…

您必须首先使用
urldecode()
解码此变量。它会将url实体更改为实际字符

尝试替换为普通字符串
str\u replace(数组(“\\r\\n”、“\\r”、“\\n”)、“
”、$name)
它将替换文本,例如
\n
,而不是
新行

您必须首先使用
urldecode()
解码此变量。它会将url实体更改为实际字符

尝试替换为普通字符串
str\u replace(数组(“\\r\\n”、“\\r”、“\\n”)、“
”、$name) 它将替换文本,例如
\n
,而不是
新行

使用
urldecode()
函数,该函数将解码后的URL作为字符串返回:

<?php

echo urldecode('Line%201\nLine%202\rLine%203\r\nLine%204'); 

?>

使用
urldecode()
函数将解码后的URL作为字符串返回:

<?php

echo urldecode('Line%201\nLine%202\rLine%203\r\nLine%204'); 

?>

我怀疑这是因为发送的字符实际上是“\n”而不是换行符

GET请求可能类似于
First+line%0ASecond+line

如果无法更改请求,则可以更改替换以避开斜杠:

print str_replace(array("\\r\\n", "\\r", "\\n"), "<br>", $name);
print str\u replace(数组(“\\r\\n”、“\\r”、“\\n”)、“
”、$name);
我怀疑这是因为发送的字符实际上是“\n”而不是换行符

GET请求可能类似于
First+line%0ASecond+line

如果无法更改请求,则可以更改替换以避开斜杠:

print str_replace(array("\\r\\n", "\\r", "\\n"), "<br>", $name);
print str\u replace(数组(“\\r\\n”、“\\r”、“\\n”)、“
”、$name);
我已经试过了,但不起作用,从php网站上我也看到他们说“superglobals$\u GET和$\u请求已经被解码。在$\u GET或$\u请求中的元素上使用urldecode()可能会产生意外和危险的结果。”@justsomeguy show
var\u dump
of
$\u GET
但是从
查看源代码
@justsomeguy和值复制,我想:)是的,对不起,从查看源代码:string(32)“第1行\nLine 2\rLine 3\r\nLine 4”@justsomeguy,所以它们是普通字符,不是新行。将编辑答案。我已经尝试过了,不起作用,而且从php站点我看到他们说“superglobals$\u GET和$\u请求已经被解码。对$\u GET或$\u请求中的元素使用urldecode()可能会产生意外和危险的结果。”@justsomeguy show
var\u dump
of
$\u GET
但是从
查看源代码
@justsomeguy和值复制,我想:)是的,对不起,从查看源代码:string(32)“第1行\nLine 2\rLine 3\r\nLine 4”@justsomeguy,所以它们是普通字符,不是新行。将编辑答案。谢谢,确实是斜杠,没有出现me@justsomeguy没问题,很高兴我能帮上忙。谢谢,确实是刀砍伤,我没想到me@justsomeguy没问题,很高兴我能帮忙。