当前位置:Gxlcms > PHP教程 > php如何去掉转义字符

php如何去掉转义字符

时间:2021-07-01 10:21:17 帮助过:45人阅读

php去掉转义字符的方法:首先找到需要去除转义字符并打开源代码;然后返回一个去除转义反斜线后的字符串,代码为【string stripslashes ( string $str )】。

php去掉转义字符的方法:

string stripslashes ( string $str )

返回一个去除转义反斜线后的字符串(\' 转换为 ' 等等)。双反斜线(\\)被转换为单个反斜线(\)。

stripslashes() 是非递归的。如果你想要在多维数组中使用该函数,你需要使用递归函数。

  1. <?php
  2. function stripslashes_deep($value)
  3. {
  4. $value = is_array($value) ?
  5. array_map('stripslashes_deep', $value) :
  6. stripslashes($value);
  7. return $value;
  8. }
  9. // 范例
  10. $array = array("f\\'oo", "b\\'ar", array("fo\\'o", "b\\'ar"));
  11. $array = stripslashes_deep($array);
  12. // 输出
  13. print_r($array);
  14. ?>

以上输出:

  1. Array
  2. (
  3. [0] => f'oo
  4. [1] => b'ar
  5. [2] => Array
  6. (
  7. [0] => fo'o
  8. [1] => b'ar
  9. )
  10. )

相关学习推荐:php编程(视频)

以上就是php如何去掉转义字符的详细内容,更多请关注gxlcms其它相关文章!

人气教程排行