How to escape backslash in php

WBOY
Release: 2023-03-15 17:46:01
Original
3753 people have browsed it

In PHP, you can use the addslashes() function to escape backslashes. This function can return a string with a backslash added before predefined characters. The predefined characters include single quotes, double quotes, and backslashes. Slashes and NULL, the syntax is "addslashes (backslash string that needs to be escaped)".

How to escape backslash in php

The operating environment of this article: Windows 10 system, PHP version 7.1, Dell G3 computer

How to escape backslashes in php

addslashes() function returns a string with backslashes added before predefined characters.

The predefined characters are:

  • Single quotation mark (')

  • Double quotation mark (")

  • Backslash (\)

  • NULL

Tip: This function can be used to return the Strings and database query statement preparation strings.

The syntax is:

addslashes(string)
Copy after login

string required. Specifies the string to be escaped.

Return value: Returns escaped String.

The example is as follows:

<?php 
$str = addslashes(&#39;这句话的中间\有一个反斜杠,现在给他转义了&#39;);
echo($str); 
?>
Copy after login

Output result:

How to escape backslash in php

Recommended learning: "PHP Video Tutorial

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