简体   繁体   English

CodeIgniter-形式的引号

[英]CodeIgniter - Quotes in form

Let's say in my db it is a field NAME which contains text with single and double quotes: 假设在我的数据库中,这是一个字段NAME,其中包含带单引号和双引号的文本:

TEST1 "TEST2" 'TEST3' TEST1“ TEST2”“ TEST3”

now I want to edit this value in a form with below code: 现在,我想使用以下代码在表单中编辑此值:

<label for="name">Full name</label>
<?php $test = $data['name']; ?>
<input type="input" name="firma_oficjalnie" value="<?= $data['name'] ?>"/><br />

<input type="submit" name="submit" value="Submit" />

The problem is that displayed data not contains single or double quotes. 问题是显示的数据不包含单引号或双引号。 How to do it properly? 怎么做呢?

Try this: 尝试这个:

Add htmlspecialchars() on the variable. 在变量上添加htmlspecialchars()

<label for="name">Full name</label>
<?php $test = "TEST1 \"TEST2\" 'TEST3'"; ?>
<input type="text" name="firma_oficjalnie" value="<?php echo htmlspecialchars($test); ?>"/><br />
<input type="submit" name="submit" value="Submit" />

Under the hood: 在引擎盖下:

What happens is that it closes the value improperly since attribute has quotations inside, thats why the values get cut. 发生的事情是由于属性内部包含了引号,所以它不正确地关闭了value ,这就是为什么值被削减的原因。

Your markup without function: 您没有功能的标记:

<input type="text" name="firma_oficjalnie" value="TEST1 " test2"="" 'test3'"="">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM