Home > Backend Development > PHP Tutorial > PHP怎么去掉转义字符?

PHP怎么去掉转义字符?

PHPz
Release: 2020-09-04 15:50:50
Original
3825 people have browsed it

PHP怎么去掉转义字符?

转义字符:

\是转义字符:转义字符是一种特殊的字符常量。转义字符以反斜线"\"开头,后跟一个或几个字符。转义字符具有特定的含义,不同于字符原有的意义,故称“转义”字符。

PHP怎么去掉转义符?

在PHP中可以使用stripslashes()函数来去掉转义符。

语法;

string stripslashes ( string $str )
Copy after login

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

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);
?>
Copy after login

输出:

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

)
Copy after login

更多相关知识,请访问 PHP中文网!!

Related labels:
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template