Zend Form 解码填充数据
我在解码来自数据库的数据时遇到了一些问题。
我的数据以 utf8 格式存储在数据库中,在本例中,数据是“corrosion & Corrosion & Corrosion”。 time”,存储为“corrosion &
time”。现在我想用这些数据填充表单的字段,该字段应用了 htmlSpecialChars 过滤器。
当在浏览器中查看时,我看到: '腐蚀 &
时间'
如果我使用 html_entity_decode 我得到: '腐蚀 $amp;
time'
如果我也从表单中删除过滤器,那么我会得到: '腐蚀与无论如何
,我可以在不从字段中删除过滤器的情况下填充表单吗?
Im having a bit of an issue with decoding data coming from a database.
My data is stored in the database as utf8, for this instance the data is 'corrosion & time', which is stored as 'corrosion &
time'. Now i want to populate a field of the form with this data, this field has a htmlSpecialChars filter applied.
When viewed in the browser I see:
'corrosion &
time'
If I use html_entity_decode i get:
'corrosion $amp;
time'
and if i also remove the filter from the form i then get:
'corrosion & time'
Is there anyway i can populate the form without removing the filter from the field?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您必须在填充表单之前对数据进行解码,过滤器不应应用于来自表单的数据,直到发布数据为止,这将在调用
getValues()
时重新应用过滤器。如果您知道使用
htmlspecialchars
来编码数据,则使用htmlspecialchars_decode
来解码数据。you are going to have to decode the data before populating the form, the filter should not be applied to the data coming from the form until it's posted which will reapply the filter when
getValues()
is called.If you know you used
htmlspecialchars
to encode the data then usehtmlspecialchars_decode
to decode the data.我认为一个好的解决方案是创建自定义 Zend_Filter。在自定义过滤器中,使用 htmlspecialchars_decode() 转换诸如 < code>& 回到
&
。I think a good solution would be to create a custom Zend_Filter. Within your custom filter, use htmlspecialchars_decode() to convert things such as
&
back to&
.