Javascript 如何从文本区域获得与原始输入相同的文本显示

Javascript 如何从文本区域获得与原始输入相同的文本显示,javascript,php,html,Javascript,Php,Html,我一直在尝试格式化从文本区域获取的字符串。我想让它看起来像它原来从文本区输入。你会发现我已经使用了很多功能,所以,如果不需要使用,请告诉我 PHP 但下面是我得到的结果,我知道这是因为我使用了strip\u标签。现在,我不知道,请帮忙。您将看到一些文本消失,等 #include using namesspace std; int main(){ return 0; } The most tragic thing in the world is a man of genius who i

我一直在尝试格式化从文本区域获取的字符串。我想让它看起来像它原来从文本区输入。你会发现我已经使用了很多功能,所以,如果不需要使用,请告诉我

PHP

但下面是我得到的结果,我知道这是因为我使用了
strip\u标签
。现在,我不知道,请帮忙。您将看到一些文本消失,

#include

using namesspace std;

int main(){
return 0;
}

The most tragic

thing in the world

is a man of genius who is not a man of honor.
另一个例子是,如果这是一个输入,它应该显示相同的内容。但是对于我的代码,没有任何显示

<textarea rows="7" cols="50" onkeyPress="return addP(event,this)"></textarea> 

添加

对于新行,请使用
PHP\u EOL
变量,或将

替换为
\n


尝试添加$detail=htmlspecialchars($detail);它似乎起作用了,但真正的新产品线也被取代了。它们以单行显示。请尝试同时使用
nl2br()
#include

using namesspace std;

int main(){
return 0;
}

The most tragic

thing in the world

is a man of genius who is not a man of honor.
<textarea rows="7" cols="50" onkeyPress="return addP(event,this)"></textarea> 
$detail = htmlspecialchars($detail);