4 recommended articles about escaping slashes

黄舟
Release: 2023-03-09 13:56:02
Original
1350 people have browsed it

Preface Recently, when I saved the link crawled by a crawler to the mysql database, I found that when I saved the link using json_encode, escape characters were displayed in the database. I did not need this escape, and it did not look like it. Clear and takes up storage space. Later, I found that by default, using json_encode to convert an array to json format will automatically escape strings containing slashes in the data. However, sometimes we do not need to escape them. This article talks about 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.

1. In PHP, let json_encode not automatically escape the slash "/"

4 recommended articles about escaping slashes

Introduction: This article mainly shares with you two methods on how to prevent json_encode from automatically escaping the slash "/" in PHP. The article gives details. The sample code is believed to be of certain reference value to everyone. Friends who need it can take a look below.

2. Issues related to character escaping

Introduction: Character escaping issues such as this string [td ]For God's sake! [/td] I escaped the single quotes and saved them in the database. When displaying the articles, I found that the articles all had escaped slashes. Instead of saving it directly into the database without escaping, sometimes errors may occur when inserting into the database. What should I do? //Convert some special characters function format_html($str){ $str = str_repl

3. Why do you need to escape? Solution

Introduction: Why do we need to escape str_replace(''\,'/',dirname(__FILE__))); The red part above is the escaped slash, why do we need to escape---- --Solution----------------------Because it is a special character. ------Solution----------------------Just to turn it into an ordinary character and make it lose its linguistic meaning

4. Character escaping related issues

Introduction: Character escaping issues such as this string [td]For God's sake! [/td]I escaped the single quotes and stored them in the database. When displaying the articles, I found that the articles all had escaped slashes. Instead of saving it directly into the database without escaping, sometimes an error will occur when inserting into the database. What should I do? //Convert some special characters function format_html($str){ $str = str_repl


The above is the detailed content of 4 recommended articles about escaping slashes. For more information, please follow other related articles on the PHP Chinese website!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!