Home > Backend Development > PHP Problem > How to remove backslashes in escaped strings in php

How to remove backslashes in escaped strings in php

藏色散人
Release: 2023-03-04 09:14:01
Original
3329 people have browsed it

php去掉斜杠的实现方法:首先创建一个PHP示例文件;然后定义一个“delete_fxg”方法;接着通过“$array[$k] = stripslashes($v);”方法去掉反斜杠字符即可。

How to remove backslashes in escaped strings in php

推荐:《PHP视频教程

PHP去掉转义后字符串中的反斜杠\函数stripslashes 

addslashes函数主要是在字符串中添加反斜杠对特殊字符进行转义,stripslashes则是去掉转义后字符串中的反斜杠\,比如当你提交一段json数据到PHP端的时候可能会遇到json字符串中有\导致json_decode函数无法将json数据转换成数组的情况,这时你就需要stripslashes函数。

该函数用于清理从数据库或 HTML 表单中取回的数据。

例子

输出:

Who's John Adams?
<?php
function delete_fxg(&$array) {
         while(list($k,$v) = each($array)) {
               if (is_string($v)) {
                   $array[$k] = stripslashes($v);//去掉反斜杠字符
               }
               if (is_array($v))  {
                   $array[$k] = delete_fxg($v);//调用本身,递归作用
              }
        }
        return $array;
}
$str[0][1]="123123\\\\";
$str[0][2]="456456\\\\";
delete_fxg($str);
print_r($str);
?>
Copy after login

The above is the detailed content of How to remove backslashes in escaped strings in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template