PHP Escape Characters

Escape characters are used to represent characters that are difficult or impossible to type directly in a string, or to insert special characters within a string. These escape characters are typically represented with a backslash (\) followed by a character or a sequence.


Common Escape Characters in PHP


Here’s a list of commonly used escape sequences in PHP:

Escape Sequence

Description

Example

\'

To include single quotes inside a string

echo 'It\'s a sunny day!'


Try it yourself

\"

To include double quotes inside a string

echo "She said, \"Hello!\"";


Try it yourself

\\

To include a literal backslash (\)

echo "C:\\Program Files\\PHP";


Try it yourself

\n

To insert newline characters (\n) 

echo "Hello\nWorld!";


Try it yourself

\r

Moves the cursor to the start of the line

echo "Hello World\rPHP";


Try it yourself

\t

It inserts a horizontal tab space

echo "Name\tAge\nJohn\t25"; 


Try it yourself

\f

Form feed(Rarely used)

"Text\fEnd"

\xXX

Hexadecimal character (XX is a two-digit hex number)

echo "\x48\x65\x6c\x6c\x6f";


Try it yourself

\u{XXXX}

Unicode escape (for characters above 255)

echo "Hello \u{1F600}";

Try it yourself


Whereisstuff is simple learing platform for beginer to advance level to improve there skills in technologies.we will provide all material free of cost.you can write a code in runkit workspace and we provide some extrac features also, you agree to have read and accepted our terms of use, cookie and privacy policy.
© Copyright 2024 www.whereisstuff.com. All rights reserved. Developed by whereisstuff Tech.