php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #9437 Function stripslashes works not correct, as i think
Submitted: 2001-02-24 13:52 UTC Modified: 2001-03-20 06:09 UTC
From: A dot Ivanov at tu-bs dot de Assigned:
Status: Closed Package: Strings related
PHP Version: 4.0.4pl1 OS: FreeBSD 4.2
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: A dot Ivanov at tu-bs dot de
New email:
PHP Version: OS:

 

 [2001-02-24 13:52 UTC] A dot Ivanov at tu-bs dot de
magic_quotes_gpc = Off | On

<?
$text = "begin\\\\\\\\\\\\\end<br>";	// 13 backslashes 	
echo $text; // will print "begin\\\\\\\end" 7 backslashes 	

// Ok. We think that backslash is a special symbol
// to change the meaning of the next character,
// so in the reality we have 6 backslashes and one
// sequence "\a" but this mean nothing so we
// print "\a" like a plain text.
// It's alright. I have no question.

// then...
$text2 = stripslashes($text);	
echo $text2;
// will print "begin\\\end"  3 backslashes

// WHY ????
// If the backslash is an ordinary symbol
// the function "stripslashes" should remove
// all of it.
// If the backslash is a special symbol, that
// understood by example showed above, then
// this function should remove 6 real slashes
// and echo will print "begin\end".

// So, if i need realy and correct remove all slashes
// from the string i should use following algorithm:

while(preg_match("/\\\/",$str))
$str = stripslashes($str);

// and i find it not so pretty............

?>

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-03-20 05:51 UTC] stas@php.net
The function works right. Meaning of stripslashes is reverse
of addslashes. Addslashes "escapes" the special characters,
i.e. adds slash to each of them. The slash itself is special
charactet, too. Stripslashes removes escapes, as if they
would be added by addslashes, i.e. \\ is converted back to
\. The \e escape is converted back to e. So you get three
\\-s to \ and one \e to e - leaving three slashes, exactly.
 [2001-03-20 06:09 UTC] A dot Ivanov at tu-bs dot de
>The function works right. Meaning of stripslashes is reverse

I don't think so.

>of addslashes. Addslashes "escapes" the special characters,
>i.e. adds slash to each of them. The slash itself is special
>charactet, too. Stripslashes removes escapes, as if they
>would be added by addslashes, i.e. \\ is converted back to
>\. The \e escape is converted back to e. So you get three
>\\-s to \ and one \e to e - leaving three slashes, exactly.

Ok. Say me please, what should i get for
stripslashes("\\\\\\\\\\"); ???

 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Thu Oct 28 05:03:34 2021 UTC