我正在重新设计一个新的网站,我的数据库表需要整理一下。
在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是正确的,但是如果数据已转义,请不要使用它,请在数据上使用反斜杠。
<?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];
?>
输出:
条状斜杠删除所有不必要的\
这很简单,但很烦人,但我们必须这样做!
然后重新插入。
关于php - 整理数据(删除br和斜杠),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/5058407/