php method to escape single quotes: Use the [addslashes()] function to add a backslash before the specified predefined character. The syntax is [addslashes(string)]. String is required and is required to be checked. String.
The operating environment of this tutorial: Windows 7 system, PHP version 5.6, DELL G3 computer.
php method of escaping single quotes:
PHP addslashes() function
Definition and usage
addslashes()
The function adds a backslash before the specified predefined character.
These predefined characters are:
Single quote (')
Double quote (")
Backslash(\)
NULL
##Syntax
addslashes(string)
Parameter Description
string Required. Specifies the string to be checked.Tips and commentsTips: This function can be used to store Prepare appropriate strings for strings in the database and database query statements. Note: By default, the PHP directivemagic_quotes_gpc is on for all GET , POST and COOKIE data automatically run addslashes().
magic_quotes_gpc escaped, because this will cause double-layer escaping. Encountered In this case, you can use the function
get_magic_quotes_gpc() to detect.
Example
In this example, we want to add the Predefined adding backslash:<?php$str = "Who's John Adams?";echo $str . " This is not safe in a database query.<br />";echo addslashes($str) . " This is safe in a database query.";?>Output:
Who's John Adams? This is not safe in a database query.Who\'s John Adams? This is safe in a database query.Generally used in the following form
if(!(get_magic_quotes_gpc())) { $_GET = addslashes($_GET); $_POST = addslashes($_POST); $_COOKIE = addslashes($_COOKIE); }
Related video recommendations:
The above is the detailed content of How to escape single quotes in php. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 English version
Recommended: Win version, supports code prompts!

SublimeText3 Linux new version
SublimeText3 Linux latest version

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

SublimeText3 Mac version
God-level code editing software (SublimeText3)
