PHP 4.0 Bug #9437 Updated: Function stripslashes works not correct, as i think

From: Date: Tue, 20 Mar 2001 10:51:36 +0000
Subject: PHP 4.0 Bug #9437 Updated: Function stripslashes works not correct, as i think
Groups: php.dev 
Request: Send a blank email to php-dev+get-49474@lists.php.net to get a copy of this message
ID: 9437 Updated by: stas Reported By: A.Ivanov@tu-bs.de Old-Status: Open Status: Closed Bug Type: Strings related Assigned To: Comments: 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. Previous Comments: --------------------------------------------------------------------------- [2001-02-24 13:52:52] A.Ivanov@tu-bs.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 "beginend". // 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............ ?> --------------------------------------------------------------------------- ATTENTION! Do NOT reply to this email! To reply, use the web interface found at http://bugs.php.net/?id=9437&edit=2

« previous php.dev (#49474) next »