php - 整理数据(删除 br 和斜杠)

标签 php mysql

我正在重新设计一个新网站,我的数据库表需要整理一下。

在 mysql 表中,我有一个如下所示的数据:

text text text text - he\'s text text text he\'s text text
text couldn\'t text text.<br /><br />\"I\'m text text
text text. We\'re text <br /><br />text text

我需要删除所有斜杠 () 并删除所有
。这样做的最佳方法是什么?

从现在开始,我将在添加数据时使用mysql_real_escape_string()。查看使用

nl2br()

最佳答案

确保 magic_quotes_gpc 已关闭,这是一个很好的做法。您始终可以使用解析数据库并将其全部重新插入。

str_replace 是正确的,但如果数据已转义,请不要使用它,请在数据上使用 stripslashes。

<?php
    $row = array(
        1 => 'stripslashes removes any unwanted \\\\',
        2 => 'it\'s easy but annoying but we must do it!'
    );
    foreach ($row as $key=>$record) {
        $escaped[$key] = stripslashes($record);
    }
    echo $escaped[1].'<br />';
    echo $escaped[2];
?>

输出:

stripslashes removes any unwanted \

it's easy but annoying but we must do it!

然后重新插入。

关于php - 整理数据(删除 br 和斜杠),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5058407/

相关文章:

php - 搜索不会发生在 Grocery 店里

java - 将参数从 Android 获取到 PHP 文件以进行 SQL 查询时遇到问题

php - 在 PHP 代码中集成 PayPal

mysql - 查找 SQL 查询 LIKE ('1077%' ) 运算符 ON DATA

javascript - 在NodeJS中,有没有类似dependent : :destroy in Ruby for associated records?的方法

mysql - R - 使用 ""将日期/时间变量推送到 SQL 查询中

java - 使用mysql、jdbc创建表

mysql - 如何获取存储在 SQL 数据库中的图像并将其显示在轮播中? ( rails 上的 ruby )

PHP 命名空间 - 如何包含不在命名空间中的第三方库?

php - 即使在滚动后也能固定表格标题的位置