简体   繁体   English

ECHO和PRINT是否自动转义单引号?

[英]Do ECHO and PRINT automatically escape single quotes?

I'm just working my way through PHP from ASP, so seeing a few irregular things happening (irregular to me only of course). 我只是通过ASP中的PHP进行工作,因此看到了一些不规则的事情发生(当然,对我来说只是不规则的)。

I have a search textbox, when somebody makes a search I'd like to keep the current search term in the textbox. 我有一个搜索文本框,当有人进行搜索时,我想将当前搜索词保留在文本框中。 I have done this by storing the term in a SESSION and echoing it in the textbox value. 我通过将术语存储在SESSION中并将其回显到文本框值中来完成此操作。

<input type="text" value="<? echo $_SESSION['search_str'] ?>">

Which works okay but if I search for something with an apostrophe, the apostrophe has automatically become escaped and is now showing in the textbox with a slash and apostrophe. 可以,但是如果我搜索带有撇号的内容,则撇号会自动转义,并且现在在文本框中显示为斜杠和撇号。

Before I go and un-escape the string, which I never escaped, is this how it's meant to be or have I missed something somewhere. 在我开始转义之前,从未逃脱过的字符串就是我要错过某处的意思。

It's semi-automagically (ie it depends on the configuration) and is imho one of the darker chapters of php. 它是半自动的(即取决于配置),是php较暗的一章之一。 If the road to hell is paved with good intentions one of the tiles has the inscription "magic quotes". 如果通向善意的地狱之路是其中一块,则上面刻着“魔术引号”。

see http://docs.php.net/magic_quotes 参见http://docs.php.net/magic_quotes

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

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