Home  >  Article  >  Backend Development  >  How to remove escape characters in php

How to remove escape characters in php

coldplay.xixi
coldplay.xixiOriginal
2020-08-15 15:21:257523browse

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

How to remove escape characters in php

php去掉转义字符的方法:

string stripslashes ( string $str )

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

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

<?php
function stripslashes_deep($value)
{
    $value = is_array($value) ?
                array_map(&#39;stripslashes_deep&#39;, $value) :
                stripslashes($value);
    return $value;
}
// 范例
$array = array("f\\&#39;oo", "b\\&#39;ar", array("fo\\&#39;o", "b\\&#39;ar"));
$array = stripslashes_deep($array);
// 输出
print_r($array);
?>

以上输出:

Array
(
    [0] => f&#39;oo
    [1] => b&#39;ar
    [2] => Array
        (
            [0] => fo&#39;o
            [1] => b&#39;ar
        )
)

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

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

Statement:
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