Home >Backend Development >PHP Problem >How to not escape backslashes in php
How to prevent backslash escaping in php: 1. Use "str_replace("\/", "/", json_encode($a));"; 2. Use "json_encode($a, JSON_UNESCAPED_SLASHES)".
The operating environment of this article: Windows7 system, PHP7.1 version, DELL G3 computer
php How to prevent backslash conversion Meaning?
How to use json_encode without automatically escaping slashes.
For the following array $a, there are two ways to solve it:
$a = array( 'http://www.baidu.com', 'http://www.baidu.com', 'http://www.baidu.com', 'http://www.baidu.com', 'http://www.baidu.com' );
One, regular replacement:
$a = str_replace("\/", "/", json_encode($a));
var_dump($a);
Second, if the PHP version is 5.4 and above:
var_dump(json_encode($a,JSON_UNESCAPED_SLASHES));
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to not escape backslashes in php. For more information, please follow other related articles on the PHP Chinese website!