Home > Article > Backend Development > What is the string escape function in php
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) ".
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('What does "yolo" mean?'); 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!