Escape Characters PHP

What are Escape sequence in PHP ?

Escape sequences is the combination of the escape character \’\\\’ and a letter, are used to signify that the character after the escape character should be treated specially. if you wanted to have the string in which \”or \’ or $ should be printed then , you would need escape characters because you have double quotes inside double quotes.And if we do not want to interpolate our string then we have to use Escape sequences Here is a list of the escape sequences in PHP:

 

  1. \\\”–  Print the next character as a double quote.
  2. \\\’–   Print the next character as a single quote.
  3. \\n– Print a new line character (not always supported )
  4. \\t–  Print a tab character.
  5. \\r–  Print a carriage return (not used very often).
  6. \\$– Print the next character as a dollar.
  7.  \\\\– Print the next character as a backslash, not an escape character.Now if you want to print address of a file then you can write it like
    $MyFile = \”c:\\\\new\\\\folder1\\\\hello.txt\”;
    echo  $MyFile;            ////output will be c:\\new\\folder1\\hello.txt

Escape sequences are very important in display and handling data on server because there are various characters which are reserve in php and if we want it into report then have to use Escape sequences.

Scroll to Top