%0D%0A在调用echo时不创建换行符
Every time I try to echo a string there is no new line. I how can I make a newline when calling echo in php using the $_GET
?
here is my code:
<?php
$text = "Hello world";
$text2 = $_GET['msg'];
echo $text2
?>
and this is what I enter in the url:
http://localhost/hello.php?msg=hello%0Dworld
or this one:
http://localhost/hello.php?msg=hello%0Aworld
and even this one:
http://localhost/hello.php?msg=hello%0D%0Aworld
The echo has to be a newline please don't say I should use a different method than $_GET
. It has to be $_GET
每当我尝试回显一个字符串时,就没有新行。 我如何使用 这是我的代码: p>
这是我在网址中输入的内容: p>
或者这个: p>
甚至这一个: p>
echo必须是换行符,请不要说我应该使用与 $ _ GET code>在php中调用echo时创建换行符? p>
&lt;?php
$ text =“Hello world”;
$ text2 = $ _GET ['msg'];
echo $ text2
?&gt;
code>
http://localhost/hello.php?msg = hello%0Dworld \ n code> pre>
http://localhost/hello.php?msg = hello%0Aworld \ n code> pre>
http://localhost/hello.php?msg = hello%0D %0Aworld
code> pre>
$ _ GET code>不同的方法。 它必须是
$ _ GET code> p>
div>
While performing your exercises you are creating an HTML page.
HTML is a special markup language, which renders according to set of rules, some of them are:
-
<>
characters has a special meaning of control structures named tags - all newline characters are ignored
- to make a newline on the page, one have to use suitable tag - such as
<br>
,<p>
or whatever.
So, to make a newline appear on your page, you have to convert newline characters to tags. Either use nl2br()
function to get a <br />
tag or str_replace()
if you want any other one
Be aware that echoing any request variables without validating them is a considerable security risk! If you want to publish any application with this code it needs to be redesigned.
As common sense states, the conversion from urlencoded to the corresponding character is automatically done by php, but HTML does not render such characters, so you either need to convert them into linebreaks or enclose the message in <pre>
tags.