dongshiru5913 2016-08-11 09:47
浏览 23
已采纳

当会话数据创建值PHP时,斜杠不断出现在字符串中

I'm using session data to set the value of an event title, but with titles that contain an apostrophe, like Britain's Digital Future, a \ keeps appearing before the apostrophe. So every time I submit the form the event title gets set to Britain\'s Digital Future with more slashes appearing each time the form is submitted. For example, if I set it 3 times the new title is Britain\\\\'s Digital Future. How can I stop this from happening? It is ruining my search function because the title cannot be found with the slashes in!

HTML:

 <tr rowspan="2">
     <td>Event</td>
     <td>
         <div class="form-group ui-widget  <?php echo $errors['event_title'] ? 'has-error':''; ?>">
             <input class="form-control" id="event_title" name="event_title" placeholder="Enter event name..." aria-describedby="helpBlock" value="<?php echo $values['event_title'] ?>">
             <?php echo $errors['event_title'] ? "<span id='helpBlock' class='help-block'>{$errors['event_title']}</span>":''; ?>
         </div>
     </td>
</tr>

PHP:

if(empty($_POST['event_title'])) {
        $_SESSION['errors']['event_title'] = 'You must enter an event title!';
    }

    if(!$event_id && !empty($_POST['event_title'])) {
        $_SESSION['errors']['event_title'] = 'No event with that title was found!';
    }

    $_SESSION['values']['event_title'] = $_POST['event_title'];

$errors = $_SESSION['errors'];
$values = $_SESSION['values'];
  • 写回答

1条回答 默认 最新

  • dongying3744 2016-08-11 09:53
    关注

    use stripslashes to remove slashes http://php.net/manual/en/function.stripslashes.php

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大