Home > Article > Backend Development > How to make string unescaped in php
php method to make strings unescaped: 1. Avoid escaping by setting in the php.ini configuration file; 2. Use the stripcslashes method to avoid escaping data; 3. Avoid escaping by setting in the htaccess file data.
Recommendation: "PHP Video Tutorial"
In php, avoid data being escaped, except that you can set In addition to the php.ini configuration file method, you can also use the stripcslashes() method to avoid escaping, or you can avoid escaping by setting it in the .htaccess file. These three methods are introduced below.
php.ini configuration file settings avoid escaping
Find the php installation directory. In the installation directory, find the php.ini file and open it with Notepad.
In the opened php.ini file, look for the magic_quotes_gpc setting option. If you cannot find it, you can add magic_quotes_gpc=Off after the configuration file.
Use stripcslashes() method to avoid escaping data
Create a new php file named test.php for introduction How to avoid escaping data using stripcslashes() method.
In order to avoid garbled characters when outputting test data, header("Content-type: text/html; charset=utf-8") is used here. The encoding of the page is utf8.
In the test.php file, create a variable $data, save the escaped characters in the variable, and use stripcslashes() to remove the escaped characters.
Run the test.php file and check the output results. It can be seen that the escaped data has been successfully converted into data without escape characters. . In actual development, you can use stripcslashes() to process data to avoid obtaining escaped data.
Set in the .htaccess file to avoid escaping data
Open the .htaccess file in the root directory of the website , will add settings to the file to avoid escaping data.
In the .htaccess file, write the code php_value magic_quotes_gpc Off and add it to .htaccess to avoid data escaping. The code is as follows:
The above is the detailed content of How to make string unescaped in php. For more information, please follow other related articles on the PHP Chinese website!