php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45462 Backslash char is not listed on a string correctly
Submitted: 2008-07-09 03:10 UTC Modified: 2008-07-14 11:09 UTC
From: lgandras at hotmail dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.2.6 OS: *
Private report: No CVE-ID: None
 [2008-07-09 03:10 UTC] lgandras at hotmail dot com
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:'

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-07-14 11:09 UTC] jani@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php


 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Tue Feb 10 13:00:01 2026 UTC