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 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿