我正在重新设计一个新网站,我的数据库表需要整理一下。
在 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/