我有一个帖子表单,它将我的文本插入MySQL数据库.
我用
$post_text = mysql_real_escape_string(htmlspecialchars($_POST['text']));
Run Code Online (Sandbox Code Playgroud)
并想要替换\r\n自动添加的内容.
我试过了
$text = str_replace('\\r\\n','', $text);
$text = str_replace('\r\n','', $text);
$text = str_replace('\\R\\N','', $text);
$text = str_replace('\R\N','', $text);
$text = str_replace('/\r\\n','', $text);
$text = str_replace('/r/n','', $text);
$text = str_replace('/\R\\N','', $text);
$text = str_replace('/R/N','', $text);
Run Code Online (Sandbox Code Playgroud)
但\r\n始终包含在我的数据库条目中.
我怎样才能解决这个问题?
我在WHERE子句中使用数组创建SQL查询时遇到问题.
例如:
我的阵列:
$myarray[1] = "hi";
$myarray[2] = "there";
$myarray[3] = "everybody";
Run Code Online (Sandbox Code Playgroud)
我的MySQL声明:
SELECT * FROM myTable WHERE title='".$myarray[]."'
Run Code Online (Sandbox Code Playgroud)
有没有办法实现这一点?我自己解决了这个问题:
for(...) {
$where = $where." title='".$myarray[$count]."' OR ";
}
$where = substr($where , 0, -3);
.....
SELECT * FROM myTable WHERE ".$where."
Run Code Online (Sandbox Code Playgroud)
但是如果我的数组中有数千个条目,那么SQL语句会变得太大而且很慢,对吧?
谢谢
我有一个jquery脚本,它发布我的表单.这里是:
$(document).ready(function(){
$("form#submit").submit(function() {
var an = $('#an').attr('value');
var betreff = $('#betreff').attr('value');
var text = $('#text').attr('value');
$.ajax({
type: "POST",
url: "newmsg.php",
data: "an="+ an +"& betreff="+ betreff +"&text="+ text,
success: function(){
$('#window').html(name);
}
});
return false;
});
});
Run Code Online (Sandbox Code Playgroud)
我的newmsg.php文件
<?php if($_POST['an']=="john") { echo json_encode(array("name"=>"hi john")); } ?>
Run Code Online (Sandbox Code Playgroud)
我的问题是,我的php文件不会返回名称,所以我的div #window不会发布消息
希望你们明白......
非常感谢你