Home > Backend Development > PHP Problem > How to not escape backslashes in php

How to not escape backslashes in php

藏色散人
Release: 2023-03-15 07:36:01
Original
2679 people have browsed it

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'
);
Copy after login

One, regular replacement:

$a = str_replace("\/", "/", json_encode($a));
Copy after login

var_dump($a);

Second, if the PHP version is 5.4 and above:

var_dump(json_encode($a,JSON_UNESCAPED_SLASHES));
Copy after login

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!

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template