|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2008-07-14 11:09 UTC] jani@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Tue Feb 10 12:00:01 2026 UTC |
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:'