时间:2021-07-01 10:21:17 帮助过:45人阅读
php去掉转义字符的方法:首先找到需要去除转义字符并打开源代码;然后返回一个去除转义反斜线后的字符串,代码为【string stripslashes ( string $str )】。
php去掉转义字符的方法:
string stripslashes ( string $str )
返回一个去除转义反斜线后的字符串(\' 转换为 ' 等等)。双反斜线(\\)被转换为单个反斜线(\)。
stripslashes()
是非递归的。如果你想要在多维数组中使用该函数,你需要使用递归函数。
- <?php
- function stripslashes_deep($value)
- {
- $value = is_array($value) ?
- array_map('stripslashes_deep', $value) :
- stripslashes($value);
- return $value;
- }
- // 范例
- $array = array("f\\'oo", "b\\'ar", array("fo\\'o", "b\\'ar"));
- $array = stripslashes_deep($array);
- // 输出
- print_r($array);
- ?>
以上输出:
- Array
- (
- [0] => f'oo
- [1] => b'ar
- [2] => Array
- (
- [0] => fo'o
- [1] => b'ar
- )
- )
相关学习推荐:php编程(视频)
以上就是php如何去掉转义字符的详细内容,更多请关注gxlcms其它相关文章!