How to remove backslashes in PHP?

藏色散人
Release: 2023-04-05 19:54:01
Original
5152 people have browsed it

本篇文章主要给大家介绍PHP去掉反斜杠的实现方法,那么在PHP中有一个内置函数stripslashes(),其作用就是删除字符串中的反斜杠。下面我们就结合具体的实例,给大家介绍PHP去掉反斜杠的方法,希望对需要的朋友有所帮助!

stripslashes()函数是PHP中的一个内置函数。此函数删除字符串中的反斜杠。

语法:

stripslashes(string)
Copy after login

参数:

该函数只接受一个参数,如上面的语法所示。

说明如下:

string:这是唯一需要的参数,指定函数将在其上操作的字符串。

返回值:

该函数返回一个去掉反斜杠的字符串。

代码示例1:

<?php 
   
    $str = "PHP and\ Python";
echo stripslashes($str);
?>
Copy after login

输出:

PHP and Python
Copy after login

代码示例2:

我们将看到stripslashes()函数的数组实现。stripslashes()不是递归的。为了将这个函数应用于数组,需要一个递归函数。

<?php 
function stripslashes_arr($value)
{
    $value = is_array($value) ?
        array_map(&#39;stripslashes_arr&#39;, $value) :
        stripslashes($value);

    return $value;
}


$array = array("PH\\P ", "an\\d", " \\Java");
$array = stripslashes_arr($array);


print_r($array);
?>
Copy after login

输出:

Array
(
    [0] => PHP
    [1] => and
    [2] =>  Java
)
Copy after login

相关推荐:《PHP教程

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

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