PHP.mk документација

stripslashes

Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.

function.stripslashes.php PHP.net прокси Преводот се освежува
Оригинал на PHP.net
Патека function.stripslashes.php Локална патека за оваа страница.
Извор php.net/manual/en Оригиналниот HTML се реупотребува и локално се стилизира.
Режим Прокси + превод во позадина Кодовите, табелите и белешките остануваат читливи во истиот тек.
stripslashes

Референца за `function.stripslashes.php` со подобрена типографија и навигација.

function.stripslashes.php

stripslashes

(PHP 4, PHP 5, PHP 7, PHP 8)

stripslashesОтстранува наводници од цитиран стринг

= NULL

stripslashes(string $string): string

Отстранува наводници од цитиран стринг.

stripslashes() може да се користи ако не ја внесувате оваа податок во место (како база на податоци) што бара бегство. На пример, ако едноставно прикажувате податоци директно од HTML форма.

Параметри

string

, и враќа стринг со првиот карактер од

Вратени вредности

Враќа стринг со отстранети бекслеш. (\' becomes ' и така натаму.) Двојни бекслеш (\\се претвораат во една коса црта\).

Примери

ако е овозможен колекторот за отпадоци, stripslashes() example

<?php
$str
= "Is your name O\'reilly?";

// Outputs: Is your name O'reilly?
echo stripslashes($str);
?>

Забелешка:

stripslashes() не е рекурзивно. Ако сакате да ја примените оваа функција на повеќедимензионален список, треба да користите рекурзивна функција.

Пример #2 Користење stripslashes() на список

<?php
function stripslashes_deep($value)
{
$value = is_array($value) ?
array_map('stripslashes_deep', $value) :
stripslashes($value);

return
$value;
}

// Example
$array = array("f\\'oo", "b\\'ar", array("fo\\'o", "b\\'ar"));
$array = stripslashes_deep($array);

// Output
print_r($array);
?>

Пример #1 Пример што покажува затворачка ознака што го опфаќа последниот нов ред

Array
(
    [0] => f'oo
    [1] => b'ar
    [2] => Array
        (
            [0] => fo'o
            [1] => b'ar
        )

)

Види Исто така

  • addslashes() - Става наводници на стринг со коси црти
  • get_magic_quotes_gpc() Ја добива моменталната активна конфигурациска поставка на magic_quotes_runtime

Белешки од корисници 6 белешки

ivijan точка stefan на gmail точка com
12 години пред
Sometimes for some reason is happens that PHP or Javascript or some naughty insert a lot of  backslash. Ordinary function does not notice that. Therefore, it is necessary that the bit "inflate":

<?php
function removeslashes($string)
{
    $string=implode("",explode("\\",$string));
    return stripslashes(trim($string));
}

/* Example */

$text="My dog don\\\\\\\\\\\\\\\\'t like the postman!";
echo removeslashes($text);
?>

RESULT: My dog don't like the postman!

This flick has served me wery well, because I had this problem before.
shredder на technodrome dot com
пред 16 години
Hi, 

Here are recursive addslashes / stripslashes functions.
given a string - it will simply add / strip slashes
given an array - it will recursively add / strip slashes from the array and all of it subarrays. 
if the value is not a string or array - it will remain unmodified!

<?php

function add_slashes_recursive( $variable )
{
    if ( is_string( $variable ) )
        return addslashes( $variable ) ;

    elseif ( is_array( $variable ) )
        foreach( $variable as $i => $value )
            $variable[ $i ] = add_slashes_recursive( $value ) ;

    return $variable ;
}

function strip_slashes_recursive( $variable )
{
    if ( is_string( $variable ) )
        return stripslashes( $variable ) ;
    if ( is_array( $variable ) )
        foreach( $variable as $i => $value )
            $variable[ $i ] = strip_slashes_recursive( $value ) ;
    
    return $variable ; 
}

?>
Tom Worster
пред 17 години
A replacement that should be safe on utf-8 strings.
<?php
  preg_replace(array('/\x5C(?!\x5C)/u', '/\x5C\x5C/u'), array('','\\'), $s);
?>
o-zone на zerozone dot it
пред 17 години
If you need to remove all slashes from a string, here's a quick hack:

<?php
function stripallslashes($string) {
    while(strchr($string,'\\')) {
        $string = stripslashes($string);
    }
}
?>

Hope it's usefull , O-Zone
stoic
19 години пред
in response to crab dot crab at gmail dot com:

$value need not be passed by reference. The 'stripped' value is returned. The passed value is not altered.
hash на samurai dot fm
пред 22 години
Might I warn readers that they should be vary careful with the use of stripslashes on Japanese text. The shift_jis character set includes a number of two-byte code charcters that contain the hex-value 0x5c (backslash) which will get stripped by this function thus garbling those characters.

What a nightmare!
Навигација

Прелистувај сродни теми и функции.

На оваа страница

Автоматски outline од активната документација.

Насловите ќе се појават тука по вчитување.

Попрегледно читање

Примерите, changelog табелите и user notes се визуелно издвоени за да не се губат во долгата содржина.

Брз совет Користи го outline-от Скокни директно на главните секции од активната страница.
Извор Оригиналниот линк останува достапен Кога ти треба целосен upstream context, отвори го PHP.net во нов tab.