[英]PHP - GET url ignoring linebreaks
Okay, so here's my problem. 好的,这是我的问题。
I have "page1.php", with following code: 我有“ page1.php”,带有以下代码:
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
<textarea id="note-textarea"></textarea>
<script>
$( "#note-textarea" ).keyup( function() {
$( "#output_div" ).html( $( this ).val() );
setTimeout(function () {
var xmlhttp;
if(window.XMLHttpRequest){
xmlhttp = new XMLHttpRequest();
}else{
xmlhttp = new ActiveXObject("XMLHTTP");
}
xmlhttp.open("GET", "/upload-note?note="+$('#note-textarea').val(), true);
xmlhttp.send(null);
}, 1000);
});
</script>
</body>
</html>
And "upload-note.php", which should upload the content of the textarea from "page1.php", to a MySQL database. 还有“ upload-note.php”(应将“ page1.php”中textarea的内容上载到MySQL数据库)。 For demonstration-purpose, let's just say, that it's going to echo the content of the textfield instead. 出于演示目的,我们只说它将回显文本字段的内容。
<?php
echo($_GET['note']);
?>
Now this setup works actually just fine, BUT it's ignoring linebreaks. 现在,此设置实际上可以正常运行,但是它忽略了换行符。 Any suggestions on how to handle these? 关于如何处理这些的任何建议?
The browser ignores linebreaks ( \\n
) in HTML documents. 浏览器将忽略HTML文档中的换行符( \\n
)。 You have to change them with <br>
tags like so.. 您必须像这样用<br>
标签进行更改。
echo nl2br($_GET['note']);
Change to POST instead of GET 更改为POST而不是GET
xmlhttp.open("POST", "/upload-note", true);
xmlhttp.send("note="+$('#note-textarea').val());
... ...
echo nl2br($_POST['note']);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.