php - PHP 5.4+ 替代 set_magic_quotes_runtime
问题描述
我想从 PHP 5.4 迁移到 PHP 7... 所以我检查了 PHP 5 和 PHP 7 之间的兼容性。我发现我的代码使用的函数已被弃用:get_magi_quotes_gpc_runtime()。
由于文档不推荐任何替代方案,还有什么替代方案?
解决方案
php7 等价物是:
$magic_quotes=false;
不再支持 magic_quotes。这从来都不是一个好主意,应尽可能避免。尽管如此,由于magic_quotes 基本上只是在$_GET / $_POST / $_COOKIE 中的所有内容上运行addlashes(),因此将其移植到现代php 并不是一项艰巨的任务,您可以在wordpress 框架中找到移植到现代PHP 的magic_quotes:https ://github.com/WordPress/WordPress/blob/38676936bac7963a62e23e0d2ec260a1ae9731ea/wp-includes/formatting.php#L5453
/**
* Add slashes to a string or array of strings.
*
* This should be used when preparing data for core API that expects slashed data.
* This should not be used to escape data going directly into an SQL query.
*
* @since 3.6.0
*
* @param string|array $value String or array of strings to slash.
* @return string|array Slashed $value
*/
function wp_slash( $value ) {
if ( is_array( $value ) ) {
foreach ( $value as $k => $v ) {
if ( is_array( $v ) ) {
$value[ $k ] = wp_slash( $v );
} else {
$value[ $k ] = addslashes( $v );
}
}
} else {
$value = addslashes( $value );
}
return $value;
}
耸耸肩
推荐阅读
- angular - 更新到最新打字稿版本时,lib.dom.d.ts 文件中缺少属性的问题
- cordova - 从 Instagram 应用程序获取登录信息
- python - 计算嵌套列表中的唯一元组
- sonarqube - 获取有关 SonarQube 5.0 API 中问题的信息
- sql - var 变量问题
- django - Fat Model Skinny View:我应该把相关代码放在哪里
- python - 当数据大小大于轴时matplotlib如何决定显示什么
- html - 更改 ngx 分页 CSS
- java - Java 类/继承结构
- c# - 如何访问数据流脚本组件中的现有 ADO.NET 连接管理器