Home  >  Article  >  Backend Development  >  What is the string escape function in php

What is the string escape function in php

青灯夜游
青灯夜游Original
2021-07-05 18:53:581946browse

The string escape function in php is addslashes(). The function of this function is to add "\" to the string and escape the specified string; the syntax format is "addslashes(string) ".

"What

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

In php, string conversion The defined function is addslashes().

addslashes() function is to add \ to the string and escape the specified string. The syntax format is as follows:

addslashes($str)

Among them, $str is the string to be escaped.

In the string returned by the addslashes() function, for the purpose of database queries and other statements, backslashes are added before certain characters. These characters are single quotes ', Double quotes ", backslashes \ and NULL.

Tip: This function can be used to prepare appropriate strings stored in the database and database query statements. String.

Example:

<?php
$str = addslashes(&#39;What does "yolo" mean?&#39;);
echo($str);
?>

Output:

What does \"yolo\" mean?

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of What is the string escape function 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