The following is my code sample:
<?php
echo addcslashes('ABC','\0..\37');
?>
My output is
\A\B\C
As per the documentation, \0...\37
would escape the ASCII values between 0 and 31. But I find that capital alphabets whose ASCII values more than 31, are being escaped here. When i tried the with small letters, it is working correctly.
What should i add to make addcslashes function work for given ASCII characters?
Use double quotes so that \
-escapes will work properly:
echo addcslashes('ABC', "\0..\37");
With single quotes '\0..\37'
is interpreted as \
+ range 0..\
+ characters 37
.
For example all capital alphabets will be within that range 0..\
, which is why they were being escaped.
You need to use double quotes for the $charlist
parameter:
echo addcslashes('ABC', "\0..\37");
With single quoted string backslash does not represent a special character sequence.
Also see the manual for double quoted strings.