简体   繁体   中英

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).

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.

<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. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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