简体   繁体   English

数据库值中的PHP花括号

[英]PHP curly braces in database value

so I have an issue. 所以我有一个问题。 We have some values in our DB stored like the following: 我们在DB中存储了一些值,如下所示:

{yoyoyo}

This is great until we pull the value out of the DB using PHP. 这很好,直到我们使用PHP从数据库中提取值。 It appears to break PHP when trying to access the variable like so: 它似乎在尝试访问变量时破坏PHP,如下所示:

$result['curly'];

For some reason PHP is interpreting that as if its a variable. 出于某种原因,PHP将其解释为一个变量。

Anyone know how to escape the result from the DB so PHP interprets it as a string and not a variable? 任何人都知道如何从数据库中转义结果,因此PHP将其解释为字符串而不是变量?

Thanks! 谢谢!

You could use htmlentities - http://php.net/manual/en/function.htmlentities.php 您可以使用htmlentities - http://php.net/manual/en/function.htmlentities.php

This will convert all characters to html entities. 这会将所有字符转换为html实体。 You can also in the future store things that don't need to be used as variables to html entities before putting them in the database to avoid this problem. 您可以在将来将不需要用作变量的内容存储到html实体中,然后再将它们放入数据库中以避免此问题。

http://www.freeformatter.com/html-entities.html http://www.freeformatter.com/html-entities.html

Yeah, after further research it appears that it's pulling the string value out of the DB just fine. 是的,经过进一步研究后,它似乎正在将数据库值从数据库中拉出来。 However, later on in our code we were doing other, lets just say, inefficient stuff. 但是,稍后在我们的代码中我们正在做其他事情,让我们说,效率低下的东西。 :) :)

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

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