addslashes() 函数是 PHP 中的内置和预定义函数,用于返回包含反斜杠的字符串,并在字符串中存在的所有预定义字符之前添加前缀。 PHP的addslashes()函数有一个特殊的特点,它不考虑从函数传递的任何参数或参数。预定义字符在此函数中的行为有所不同。与 addcslashes() 函数相比,addslashes 函数略有不同,因为该函数接受需要在斜杠之前添加的指定字符,但对于 addslashes() 函数来说并不重要,因为它不允许传递任何参数并在斜杠之前附加斜杠指定的字符。
开始您的免费软件开发课程
网络开发、编程语言、软件测试及其他
语法
addslashes($string)
返回类型: 返回类型是返回在函数中添加字符串的预定义字符前面带有反斜杠的字符串。
addslashes 是 PHP 定义的字符串引用和字符串包中的一个特殊的内置函数,它为带斜杠的引号字符串生成引号。它有一个返回类型,返回具有特殊格式的字符串,字符串中的字符将以字符串为前缀:
用例将随字符串而变化,在带有这些字符的字符串之前添加前缀的字符将被转义字符集。
此函数已在 PHP 5.4.0 及更高版本后添加并开始使用,否则,在字符串上使用的所有类型的 GET、POST 和 cookie 上,默认值将被视为 magic_quotes_gpc addslashes() 函数。
有时,一旦与数据库查询合并,此函数就会表现异常。因此,在PHP使用addslashes函数时,需要根据需求类型和版本来检查和应对。由于这使得使其与数据库一起工作变得不明确,因此有时可能会出现使其与数据库注入及其相关查询同步的情况,因此非常需要为其创建特定于数据库的转义函数或准备好的语句使用。
此外,许多子字符串充当addslashes函数或作为addslashes函数的一部分,该函数包括以下函数作为其同伴:
以下是不同的示例:
此程序代表用于表示字符串的addslashes函数,并输出带有转义字符序列的生成字符串。
代码:
<!DOCTYPE html> <html> <body> <?php $str = addslashes('hope you are doing good with educba!'); echo($str); ?> </body> </html>
输出:
This program represents the addslashes function for the representation of the string with an output of the generated string with escaped sequences of characters but supporting the ambiguous behavior of the database injection.
Code:
<!DOCTYPE html> <html> <body> <?php $str = "Which car is Volkswaon?"; echo $str . " It Is safe during database injection.<br>"; echo addslashes($str) . " Safe for database injection."; ?> </body> </html>
Output:
This program represents the addcslashes() function for the representation of the string with an output of the generated string with escaped sequences of characters by adding a backslash in front of the letter W which behaves completely opposite of addslashes() function.
Code:
<!DOCTYPE html> <html> <body> <?php $str = addcslashes("Welcome Educba!","W"); echo($str); ?> </body> </html>
Output:
This program represents the addcslashes() function for the representation of the string with an output of the generated string with escaped sequences of characters by adding a backslash in front of the letter educba for adding backslashes which behave completely opposite of addslashes() function.
Code:
<!DOCTYPE html> <html> <body> <?php $str = "Thanks for revisiting the educba portal!"; echo $str."<br>"; echo addcslashes($str,'d')."<br>"; echo addcslashes($str,'c')."<br>"; echo addcslashes($str,'b')."<br>"; ?> </body> </html>
Output:
This program represents the addcslashes() function for the representation of the string with an output of the generated string with escaped sequences of characters by adding a backslash in front of the letter educba for adding multiple backslashes which behaves completely opposite of addslashes() function.
Code:
<!DOCTYPE html> <html> <body> <?php $str = "Thanks for revisiting to our portal of educba!"; echo $str."<br>"; echo addcslashes($str,'A..Z')."<br>"; echo addcslashes($str,'a..z')."<br>"; echo addcslashes($str,'a..g'); ?> </body> </html>
Output:
This program represents the HTML special characters with the elements to translate the element’s value into one value using string.
Code:
<!DOCTYPE html> <html> <body> <?php $str = "There are some good person."; echo htmlspecialchars($str); ?> <p>Translate into entities with HTML special characters with the elements to prevent browsers and prevent code running to display from input to the homepage</p> </body> </html>
Output:
The addslashes function is used to represent and traverse the string by prefixing the backslash string in front of the entire special character string and is used to quote the necessary and important string to be used simultaneously.
以上是PHP 添加斜杠()的详细内容。更多信息请关注PHP中文网其他相关文章!