By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,748 Members | 1,427 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,748 IT Pros & Developers. It's quick & easy.

addcslashes

P: n/a
Hi everyone,
>From what I understand in of addcslashes, addcslashes should add a
backslash before every character listed in the character list. I've
done a couple of experiments:

echo bin2hex(addcslashes("a","a")) gives 5c31, as expected ('\'
followed by 'a')

Next, I tried

echo bin2hex(addcslashes("\0","\0")); which gave 5c 30 30 30, which is
a backslash followed by 3 spaces. What's happening here? I would have
thought that the output would be

5c 00 (backslash followed by a null)

Taras

Feb 8 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Next, I tried
>
echo bin2hex(addcslashes("\0","\0")); which gave 5c 30 30 30, which is
a backslash followed by 3 spaces. What's happening here? I would have
thought that the output would be

5c 00 (backslash followed by a null)

Taras
Meh, I re-read the manual more closely and realised that: "while other
non-alphanumeric characters with ASCII codes lower than 32 and higher
than 126 converted to octal representation."

so 5c 30 30 30 = \ octal representation of 0

or, if the byte x01 was escaped, the result would be

5c 30 30 31 = \001 = \ octal representation of 01

What is the point of converting to an octal representation? Where
would it be used? I've never heard of this being used in the c
language..

Taras
Feb 8 '07 #2

P: n/a
"Taras_96" <ta******@gmail.comwrote in message
news:11*********************@s48g2000cws.googlegro ups.com...
Hi everyone,
>>From what I understand in of addcslashes, addcslashes should add a
backslash before every character listed in the character list. I've
done a couple of experiments:

echo bin2hex(addcslashes("a","a")) gives 5c31, as expected ('\'
followed by 'a')
Ascii lowercase 'a' is 0x61, not 0x31. 0x31 is '1'. 0x5c is indeed a
backslash. I got 61 when I tried the line above.
Next, I tried

echo bin2hex(addcslashes("\0","\0")); which gave 5c 30 30 30, which is
a backslash followed by 3 spaces.
0x30 is ascii '0' (zero), not a space (which is 0x20).
What's happening here?
Something quite odd. Since \0 is the string terminating character, it would
seem that it throws the functions a bit off. File a bug report?
Feb 8 '07 #3

P: n/a
On Feb 8, 5:26 pm, "Kimmo Laine" <s...@outolempi.netwrote:
"Taras_96" <taras...@gmail.comwrote in message

news:11*********************@s48g2000cws.googlegro ups.com...
Hi everyone,
>From what I understand in of addcslashes, addcslashes should add a
backslash before every character listed in the character list. I've
done a couple of experiments:
echo bin2hex(addcslashes("a","a")) gives 5c31, as expected ('\'
followed by 'a')

Ascii lowercase 'a' is 0x61, not 0x31. 0x31 is '1'. 0x5c is indeed a
backslash. I got 61 when I tried the line above.
Next, I tried
echo bin2hex(addcslashes("\0","\0")); which gave 5c 30 30 30, which is
a backslash followed by 3 spaces.

0x30 is ascii '0' (zero), not a space (which is 0x20).
What's happening here?

Something quite odd. Since \0 is the string terminating character, it would
seem that it throws the functions a bit off. File a bug report?
You're right about my corrections. For some reason I knew that but I
typed in the wrong things! It's not a bug, it's a documented behavoiur
- see my previous post.

Feb 9 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.