Home  >  Article  >  Backend Development  >  How to not escape backslashes in php

How to not escape backslashes in php

藏色散人
藏色散人Original
2022-01-28 10:52:402621browse

How to prevent backslash escaping in php: 1. Use "str_replace("\/", "/", json_encode($a));"; 2. Use "json_encode($a, JSON_UNESCAPED_SLASHES)".

How to not escape backslashes in php

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!

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