简体   繁体   中英

''' character shows up as “\'” in php output

I am working on a post type form. The site is wordpress based. While testing the form, I noticed that everytime I use the ''' character, when the post is posted, it prints out "\\'" instead.

For example:

Input: "Bob's birthday plans." Output: "Bob\\'s birthday plans."

How do I stop php or wordpress, whichever is responisble, from doing this?

Those are Magic Quotes , one of the most controversial features of PHP.

It is an option in PHP.ini, you should contact your hosting service and have them shut it off (Or look for the option yourself, if you are privileged enough to).

Could be magic_quotes_gpc or even worse magic_quotes_runtime .

This feature has been DEPRECATED as of PHP 5.3.0 and REMOVED as of PHP 6.0.0. Relying on this feature is highly discouraged.
[...]
When magic_quotes are on, all ' (single-quote), " (double quote), \\ (backslash) and NUL's are escaped with a backslash automatically.

There seems to be a problem with magicquotes and according to this site, the fix consists in adding the following lines to your theme file:

if ( get_magic_quotes_gpc() ) {
    $_POST      = array_map( 'stripslashes_deep', $_POST );
    $_GET       = array_map( 'stripslashes_deep', $_GET );
    $_COOKIE    = array_map( 'stripslashes_deep', $_COOKIE );
    $_REQUEST   = array_map( 'stripslashes_deep', $_REQUEST );
}

Which would translate to something like, if magic quotes are enabled, remove the slashes from those variable arrays. Therefore fixing your issue.

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