PHP addslashes() 函数

2024 年 9 月 4 日 | 阅读 1 分钟

PHP addslashes() 函数用于返回一个带反斜杠的引用字符串。它对某些字符生效

  • 单引号 (')
  • 双引号 (")
  • 反斜杠 (\)
  • NUL (NUL 字节)

语法

参数描述必需/可选
string待转义的字符串必需

示例 1

输出

Your string is :What does "WHO" mean?
By using addslashes() function the result isWhat does \"WHO\" mean?

示例 2

输出

Who's the father of PHP? This is not safe in a database query.
Who\'s the father of PHP? This is safe in a database query.

示例 3

输出

Wow' PHP?

addslashes() 的一个用例是在将被 PHP 求值的字符串中转义上述字符。

示例 4

输出

Is The Father of PHP\'Rasmus? 

下一主题PHP 字符串