php escape char – PHP Escape Sequences

php escape char \’ – To escape ‘ within single quoted string, \” – To escape “ within double quoted string, \\ – To escape the backslash, \$ – To escape $, \n – To add line breaks between string, \t – To add tab space and \r – For carriage return.

php escape char – How To Use Escape Characters in PHP?

Escape Sequence Example


Widely used Escape Sequences in PHP

The valid escape sequences in PHP are shown in the following List.

  • \’ – To escape ‘ within single quoted string.
  • \” – To escape “ within double quoted string.
  • \\ – To escape the backslash.
  • \$ – To escape $.
  • \n – To add line breaks between string.
  • \t – To add tab space.
  • \r – For carriage return.

escape sequences Example


Double Quotes and Heredoc

$name = 'Infinityknow';
echo "Welcome $name"; // "Welcome Infinityknow"
$name = 'Infinityknow';
echo <<

Alternately

$name = 'Infinityknow';
echo "Welcome {$name}"; // "Welcome Infinityknow"

Single-quoted strings ('string')

$name = 'Infinityknow';
echo 'Welcome $name'; // "Welcome $name"
$name = 'Infinityknow';
echo <<<'NOWDOC'
Welcome $name
NOWDOC;
// "Welcome $name"

Character Escaping

$name = 'Infinityknow';
echo "Welcome \$name"; // "Welcome $name"
$name = 'Infinityknow';
echo "Welcome \\$name"; // "Welcome \Infinityknow"

Tab Characters: \t and \v

echo "Welcome\tPakainfo";

//results : Welcome Pakainfo

New Lines: \r and \n

echo "Left\nLeft\nRight\nRight";

Escape character: \e

echo "\e[32mPakainfo website\e[0m \e[33mInfinityknow website\e[0";

Don't Miss : PHP Addslashes Function With Examples

I hope you get an idea about php escape char.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Comment