addcslashes

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Taras_96

    addcslashes

    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(addcsla shes("a","a")) gives 5c31, as expected ('\'
    followed by 'a')

    Next, I tried

    echo bin2hex(addcsla shes("\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

  • Taras_96

    #2
    Re: addcslashes

    Next, I tried
    >
    echo bin2hex(addcsla shes("\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


    Comment

    • Kimmo Laine

      #3
      Re: addcslashes

      "Taras_96" <taras.di@gmail .comwrote in message
      news:1170918221 .814144.39540@s 48g2000cws.goog legroups.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(addcsla shes("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(addcsla shes("\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?


      Comment

      • Taras_96

        #4
        Re: addcslashes

        On Feb 8, 5:26 pm, "Kimmo Laine" <s...@outolempi .netwrote:
        "Taras_96" <taras...@gmail .comwrote in message
        >
        news:1170918221 .814144.39540@s 48g2000cws.goog legroups.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(addcsla shes("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(addcsla shes("\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.

        Comment

        Working...