【发布时间】:2017-09-13 16:30:48
【问题描述】:
我正在使用 MySQL 和 PHP 来管理我网站上的数据。
我有一个以 TeX 格式输入的段落,其中包含许多数学公式。我想在我的数据库中插入并在其他地方检索相同的内容。
在检索时,我正在使用 mathjax 来显示数学部分。 插入数据时出现问题。
当我插入数据时
$\int f d\mu $ ( Note that this '\' is required to run the math formula)
我将插入的数据作为
$\\int f d \\mu $
有两个反斜杠而不是一个。
如何使用手动添加的反斜杠(这是必需的)来防止每次添加的反斜杠。
stripslashes() 会提供帮助或任何其他解决方案吗?
提前致谢。
<form action="" method="POST">
<input type="hidden" name="id" value=<?php echo $print->Id; ?> >
<table class="speaker-abstract" style="width:49%; float:left;">
<tr>
<th> Update the Abstract Details Here </th>
</tr>
<tr>
<td>
<label> Title of the Talk </label>
<input style="width:95%" type="text" name="title1" value="<?php echo $print->title_of_the_talk1; ?>">
</td>
</tr>
<tr>
<td>
<label> Abstract of the Talk (Type in TeX format) </label>
<textarea style="width:95%" name="abstract1" rows="10" ><?php echo $print->Abstract1; ?></textarea>
</td>
</tr>
</table>
<table class="speaker-abstract" style="width:49%; float:left;">
<tr>
<th> If any other, update the Abstract Details Here </th>
</tr>
<tr>
<td>
<label> Title of the Talk </label>
<input style="width:95%" type="text" name="title2" value="<?php echo $print->title_of_the_talk2; ?>">
</td>
</tr>
<tr>
<td>
<label> Abstract of the Talk (Type in TeX format) </label>
<textarea style="width:95%" name="abstract2" rows="10" > <?php echo $print->Abstract2; ?> </textarea>
</td>
</tr>
</table>
<input style="float:right;" type="submit" name="update_abstract" value="Submit/Update">
</form>
提交表单和显示数据的php代码如下。
<?php
$success_msg="Updated Successfull !!!";
$search= "Search the Speaker Here";
if (isset($_POST['update_abstract'])){
$id=$_POST['id'];
$title1=$_POST['title1'];
$title2=$_POST['title2'];
$abstract1=$_POST['abstract1'];
$abstract2=$_POST['abstract2'];
$update=$wpdb->update(
'Invited_Speakers_auto',
array(
'title_of_the_talk1' => $title1,
'title_of_the_talk2' => $title2,
'abstract1' => $abstract1,
'abstract2' => $abstract2
),
array( 'id' => $id )
);
if ($update==true){
echo $success_msg.$abstract1;
}else
{
$success_msg="There is an error in the update";
}
}
?>
PS:
请注意,我需要用户插入的斜线,我只需删除在 sql 插入发生时自动插入的斜线。
stipslashes()帮助我删除输出中添加的斜线。
但我想在插入时删除反斜杠。
【问题讨论】:
-
我们能看到代码吗?您可以 preg_replace 变量数据中的所有斜线并将它们替换为什么以删除它们。它正在逃避斜线。
-
您是如何将这些数据插入到您的数据库中并稍后显示的?这些额外的字符首先来自哪里?
-
stripslashes 会帮助你。它删除所有添加的斜线
-
向我们展示代码。
-
在双引号字符串中,您会看到它们被加倍,所以也许这不是问题。您使用什么代码进行插入?你是如何获取数据的?你如何显示获取的数据?除非您正在修复损坏,否则使用
stripslashes可能是错误的做法。
标签: php html mysql stripslashes