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

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题