addslashes_gpc()
云策文档标注
概述
addslashes_gpc() 是一个 WordPress 函数,用于为字符串或数组中的字符串递归添加反斜杠转义,主要用于处理 GPC(GET、POST、COOKIE)数据以防止安全问题。它实际上是 wp_slash() 的别名,简化了转义操作。
关键要点
- 函数功能:为字符串或数组递归添加反斜杠转义,适用于 GPC 数据。
- 参数:$gpc,必需,可以是字符串或数组。
- 返回值:返回转义后的字符串或数组。
- 内部实现:直接调用 wp_slash() 函数。
- 相关函数:与 wp_slash() 关联,用于数据转义。
- 使用场景:常用于 WP_Query::get_posts() 等查询处理中,确保数据安全。
- 版本历史:自 WordPress 0.71 版本引入。
代码示例
/* Example usage of addslashes_gpc() */
$data = array(
'name' => 'John's Blog',
'content' => 'It's a beautiful day.',
'meta' => array(
'author' => 'Jane's Pen',
)
);
$sanitized_data = addslashes_gpc( $data );
print_r( $sanitized_data );
原文内容
Adds slashes to a string or recursively adds slashes to strings within an array.
Parameters
$gpcstring|arrayrequired-
String or array of data to slash.
Source
function addslashes_gpc( $gpc ) {
return wp_slash( $gpc );
}
Changelog
| Version | Description |
|---|---|
| 0.71 | Introduced. |
Skip to note 2 content
Yuvrajsinh Sisodiya
/* Example usage of addslashes_gpc() */ $data = array( 'name' => 'John's Blog', 'content' => 'It's a beautiful day.', 'meta' => array( 'author' => 'Jane's Pen', ) ); $sanitized_data = addslashes_gpc( $data ); print_r( $sanitized_data );