How to escape double quotes in php

藏色散人
Release: 2023-03-08 06:08:02
Original
4069 people have browsed it

php method to escape double quotes: first create a PHP sample file; then add backlash before each double quote through the "addslashes('Shanghai is the "biggest" city in China.');" method Just use a slash to escape the string.

How to escape double quotes in php

The operating environment of this article: Windows 7 system, PHP version 7.1, DELL G3 computer.

addslashes — Quote (escape) a string using backslashes; the

addslashes() function returns a string with a backslash added before a predefined character.

The predefined characters are:

单引号(') 双引号(") 反斜杠(\) NULL
Copy after login

Tip: This function can be used to prepare strings for strings stored in the database as well as database query statements.

Note: By default, PHP automatically runs addslashes() on all GET, POST and COOKIE data. So you should not use addslashes() on already escaped strings, as this will result in double escaping. When encountering this situation, you can use the function get_magic_quotes_gpc() to detect it.

Recommended: "PHP Video Tutorial"

Grammar

addslashes(string)
Copy after login

Parameters

string required. Specifies the string to be escaped.

Add a backslash before each double quote ("):

Copy after login

Output:

Shanghai is the \"biggest\" city in China.
Copy after login

The above is the detailed content of How to escape double quotes 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
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!