|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2004-06-07 21:53 UTC] todd at magnifisites dot com
Description: ------------ The addcslashes manual page states that characters with ASCII code lower than 32 and higher than 126 are converted to octal representation. It then instructs us to use the ord() function to find the ASCII value for a character. I have found discrepancies in my tests (I've tested on both Linux and Windows servers). The octal representation conversion seems to occur completely throughout the range including 32 through 126, inclusive, rather than outside that range. Reproduce code: --------------- $null = NULL; $var = "Hi there\" dollar $ amper \t sand & and single ' quote NULL $null"; $escaped_var = addcslashes($var, "\0\9\34\36\38\39"); print $escaped_var; Expected result: ---------------- Hi there\" dollar \$ amper \t sand \& and single \' quote NULL Actual result: -------------- Hi there" dollar $ amper sand & and single ' quote NULL PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 19 14:00:01 2025 UTC |
Thanks for the response. To clarify, which statement in the addcslashes() documentation is incorrect? "Use the ord() function to find the ASCII value for a character." <?php // OK, I'll give it a shot: print ord('$'); // prints 36 ?> OK, I agree -- the ASCII value for the dollar sign character is 36. Now, back to the documentation... "charlist like "\0..\37", which would escape all characters with ASCII code between 0 and 37." Example 1. addcslashes() example <?php $escaped = addcslashes($not_escaped, "\0..\37!@\177..\377"); ?> <?php // Following suit, I want to escape the dollar // sign ($) character which has ASCII code 36, // as just established in the previous code: $escaped = addcslashes('$', "\36"); print $escaped; // prints $ // ...whereas... $escaped = addcslashes('$', "\44"); // octal print $escaped; // prints \$ ?> Conclusion: The documentation states that characters with ASCII code lower than 32 and higher than 126 are converted to octal representation. I can understand that. However, as this example demonstrates, it seems the charlist parameter expects octal values, for any range, not just those characters with ASCII values < 32 or > 126. Still confused. Is it the second statement that is incorrect? Does the charlist parameter always expect octal values? Thanks -- Todd