【发布时间】:2017-09-11 19:53:46
【问题描述】:
我有一个填充的 mysql 数据库,它输出通过 angularjs 消费和显示的 json 数据。 数据库中的一些文本字符串有转义引号和双引号,例如:
Do you have at least a bachelor\'s degree in child development?
或
asking the children to address you as \"Ma\'am\" or \"Sir\" to formalize things
问题是 angularjs 仍然显示带有转义引号的字符串。避免这种情况的最佳方法是什么?我是否在数据库上进行搜索和替换,将转义的子字符串 (\',\") 替换为其他内容? 输出显示在 angularjs 中,就像使用 ng-model 指令一样:
...
<div class="bs form-group" ng-if="quiz.quizmanager.quiz.questions[quiz.activeQuestion].quiz_question_type === 'text'">
<input type="text" class="form-control" ng-model="quiz.quizmanager.quiz.questions[quiz.activeQuestion].answer"
ng-change="quiz.selectAnswer(0, quiz.quizmanager.quiz.questions[quiz.activeQuestion].quiz_question_type)"
/>
</div>
...
【问题讨论】:
-
是的,您可以进行这样的查询,或者您可以在输出数据之前使用
stripslashes。不过,它是如何开始的呢?在将其绑定到准备好的语句以插入它之前,您是否对其进行了转义? -
@Don'tPanic 在将响应发送到 Angular 之前,由于我正在对数组进行 json_encoding,因此带斜杠不起作用。我仍然有 db insert 语句。它们看起来像这样:
-
(70,'Kickin\\\' Kitchens','Kickin\\\' Kitchens',0,0,'2017-07-06 00:00:00',NULL,0, '00:20:00'),
-
(90,9,'视频中,\\\\"intersectionism\\\\"的概念定义为:','radio'),
-
您可以在将文本添加到您要发送到
json_encode的数组之前先在文本上使用stripslashes吗?json_encode将在需要的地方再次添加自己的斜线。
标签: javascript php mysql angularjs