1

I am trying ot learn how to escape simple characters. I print the ASCII of the character >. But when I print it after using the function addcslashes..nothing is escaped. Why is that?

     $da=ord('>'); 
     echo $da."<br/>";
     $not_escaped="><?";
      $escaped = addcslashes($not_escaped, "\61...\64");
      echo  $escaped;

I followed their documentations..but my example above doesnt work. Thye also use 2 seperators !@ between the range of ASCII number range..what does it mean?

$escaped = addcslashes($not_escaped, "\0..\37!@\177..\377");
BlackFire27
  • 1,470
  • 5
  • 21
  • 32

1 Answers1

1

The ASCII codes in the $charlist are octal, not decimal. So to escape ">" (decimal: 62, octal: 76), use this code:

$escaped = addcslashes($not_escaped, "\76");

For a range, use two dots and not three ('a..z', not 'a...z').

pencil
  • 1,165
  • 8
  • 20
  • Their documentation dont say so..if i want two ranges..do I include these symbols? – BlackFire27 Feb 18 '12 at 12:56
  • > characters with ASCII codes lower than 32 and higher than 126 converted to *octal representation*. – pencil Feb 18 '12 at 13:10
  • 1
    Multiple ranges: `$escaped = addcslashes($not_escaped, "a..c!@k..m"); // escape a-c and k-m` – pencil Feb 18 '12 at 13:11
  • what about characters between 32 and 126.. is tehir representation is decimal – BlackFire27 Feb 18 '12 at 13:13
  • No, all the ASCII codes should be octal. ;) > they are converted in C-like style, [...] to octal representation. – pencil Feb 18 '12 at 13:19
  • lol..why the hell did they say that: characters with ASCII codes lower than 32 and higher than 126 converted to octal representation. ... if all of them should be ocatal? – BlackFire27 Feb 18 '12 at 13:20