Get the App
SLTechnology News&Howtos  ›  Development  › 

How to remove the backslash in php json_encode

Shulou Source: shulou.com Published: 2022-06-02 03:23:22 11月13日 Update

This article mainly explains "php json_encode how to remove backslashes", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let Xiaobian take you to learn "php json_encode how to remove backslashes"!

php json_encode Do not backslash implementation method: 1, use PHP's own parameter "JSON_UNESCAPED_SLASHES";2, by "str_replace("\\/", "/", json_encode($url));" replacement.

Operating environment: Windows 7 system, PHP7.1 version, DELL G3 computer

php json_encode Do not backslash how to achieve?

Resolves backslashes in json_encode formatted data

Make json_encode formatted data without backslashes

Problem Description:

When we return json format data to the front end or server, after converting with json_encode format, there will always be backslashes, and the default json_encode will escape/to\/, as follows:

"data":"http:\/\/www.****. com\/static\/admin\/upload\/1545030861.jpg"

What we want is the following format:

"data":"http://www.****. com/static/admin/upload/1545023021.jpg"

Solution:

1. Use PHP's built-in parameters: JSON_UNESCAPED_SLASHES

$url = 'http://www.chyblog.com/static/admin/upload/1545023021.jpg';echo json_encode($url,JSON_UNESCAPED_SLASHES);

2. You can also replace it directly.

$url = 'http://www.chyblog.com/static/admin/upload/1545023021.jpg';echo str_replace("\\/", "/", json_encode($url));

The result is the same!

At this point, I believe everyone has a deeper understanding of "php json_encode how to remove backslashes", so let's actually operate it! Here is the website, more related content can enter the relevant channels for inquiry, pay attention to us, continue to learn!

Tags: Slash format data content parameter method time problem learning practical deeper interest front end method picture address practicality practical simple operation more Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi OPPO Reno Xiaomi MariaDB Shulou Information