ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> php-dev
php-dev
#45462 [NEW]: Backslash char is not listed on a string correctly
by Lgandras At Hotmail Dot Com other posts by this author
Jul 8 2008 8:10PM messages near this date
[PHP-DEV] Re: [PHP-CVS] cvs: php-src(PHP_5_3) /win32/build DSP.README block.template.dsw buildconf.js config.w32 confutils.js projectgen.js template.dsp template.dsw | #45462 [Opn->Bgs]: Backslash char is not listed on a string correctly
From:             lgandras at hotmail dot com
Operating system: WINDOWS AND LINUX
PHP version:      5.2.6
PHP Bug Type:     Scripting Engine problem
Bug description:  Backslash char is not listed on a string correctly

Description:
------------
When a string contains backslashs, they are shown on a way, but kept
differntly on the string. This is annoying when a string needs to be parsed
to know if a quote is being escaped.

Reproduce code:
---------------
$stringA = "\\'";    # returns \'
$stringB = "\\\'";   # returns \\'
$stringC = "\\\\'";  # returns \\'
$stringD = "\\\\\'"; # returns \\\'

# etc.. I don't have problem with it.
# But! this is the way it is shown!
# internally the string is kept how the programmer wrote it
# how are you supposted to known with php routines
# that $stringB escapes the quote and $stringC does not!
# using stripslashes is not an option,
# because it could delete some backslashes you want to keep.
# 
# 
# I've seen other bugs, where it is told
# that normal functioning of stripslashes
# is to delete all the "first" slashes,
# but then is not possible to parse a string
# even with regular expressions to know what
# a parser like mysql would understand of my
# string.
# 
# In other words, backslashes are still there,
# but you can't know it!

$stringB == $stringC; # devolves true, in the end is right, but not now.
$stringB === $stringC; # also true (in the end), but not for mysql


substr($stringB, 0, 1) === substr($stringC, 0, 1);
substr($stringB, 1, 1) === substr($stringC, 1, 1);
substr($stringB, 2, 1) === substr($stringC, 2, 1);

# again, on the last 3 examples it returns true,
# but it doesn't let me know if the quote is being escaped or not.
# If questions are done, i need to parse a mysql string!
# My other solution is that str_replace and/or regular
# expression functions handle this issues in an adecuate way

echo "B:";
echo str_replace('\\', '', $stringB);
echo "<br /> C:";
echo str_replace('\\', '', $stringC);

Expected result:
----------------
B:\'
C:'
# note that this is in concordance with what the manual says

Actual result:
--------------
B:'
C:'

-- 
Edit bug report at http://bugs.php.net/?id=45462&edit=1
-- 
Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=45462&r=trysnapshot52
Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=45462&r=trysnapshot53
Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=45462&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=45462&r=fixedcvs
Fixed in release:             http://bugs.php.net/fix.php?id=45462&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=45462&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=45462&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=45462&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=45462&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=45462&r=notwrong
Not enough info:              http://bugs.php.net/fix.php?id=45462&r=notenoughinfo
Submitted twice:              http://bugs.php.net/fix.php?id=45462&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=45462&r=globals
PHP 4 support discontinued:   http://bugs.php.net/fix.php?id=45462&r=php4
Daylight Savings:             http://bugs.php.net/fix.php?id=45462&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=45462&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=45462&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=45462&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=45462&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=45462&r=mysqlcfg
Thread:
Lgandras At Hotmail Dot Com
jani

Privacy Policy | Email Opt-out | Feedback | Syndication
© 2004 ActiveState, a division of Sophos All rights reserved