小编nja*_*jak的帖子

用PHP替换\ r \n

我有一个帖子表单,它将我的文本插入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始终包含在我的数据库条目中.

我怎样才能解决这个问题?

php mysql replace insert

34
推荐指数
3
解决办法
6万
查看次数

Jquery - 如果页面已加载

有没有什么技巧如何在javascript中启动一个函数,它在页面完全加载时启动?

javascript jquery

13
推荐指数
2
解决办法
3万
查看次数

SQL Query中的数组?

我在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语句会变得太大而且很慢,对吧?

谢谢

php mysql

9
推荐指数
2
解决办法
6万
查看次数

Jquery POST Json返回

我有一个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不会发布消息

希望你们明白......

非常感谢你

jquery post json

6
推荐指数
1
解决办法
2万
查看次数

标签 统计

jquery ×2

mysql ×2

php ×2

insert ×1

javascript ×1

json ×1

post ×1

replace ×1