BlackFire27
BlackFire27

Reputation: 1550

Cant escape a string with addcslashes()

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");

Upvotes: 1

Views: 714

Answers (1)

pencil
pencil

Reputation: 1145

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').

Upvotes: 1

Related Questions