Home >Backend Development >PHP Problem >How to make string unescaped in php

How to make string unescaped in php

藏色散人
藏色散人Original
2020-11-17 09:17:045928browse

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.

How to make string unescaped in php

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.

How to make string unescaped in php

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.

How to make string unescaped in php

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.

How to make string unescaped in php

In the test.php file, create a variable $data, save the escaped characters in the variable, and use stripcslashes() to remove the escaped characters.

How to make string unescaped in php

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.

How to make string unescaped in php

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.

How to make string unescaped in php

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:

How to make string unescaped in php

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn