What is the string escape function in php

青灯夜游
Release: 2023-03-11 09:16:01
Original
1976 people have browsed it

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)
Copy after login

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);
?>
Copy after login

Output:

What does \"yolo\" mean?
Copy after login

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!

Related labels:
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