Home  >  Article  >  Backend Development  >  How to escape backslash in php

How to escape backslash in php

WBOY
WBOYOriginal
2022-04-13 11:44:473731browse

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)

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); 
?>

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!

Statement:
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