Heim  >  Artikel  >  Backend-Entwicklung  >  Wie entferne ich Backslashes in PHP?

Wie entferne ich Backslashes in PHP?

藏色散人
藏色散人Original
2019-04-12 10:02:405101Durchsuche

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

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

语法:

stripslashes(string)

参数:

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

说明如下:

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

返回值:

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

代码示例1:

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

输出:

PHP and Python

代码示例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);
?>

输出:

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

相关推荐:《PHP教程

Das obige ist der detaillierte Inhalt vonWie entferne ich Backslashes in PHP?. Für weitere Informationen folgen Sie bitte anderen verwandten Artikeln auf der PHP chinesischen Website!

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn