Posted inphp

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.

I am Jaydeep Gondaliya , a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, JavaScript, jQuery, Laravel, CodeIgniter, VueJS, AngularJS and Bootstrap from the early stage.

Leave a Reply

Your email address will not be published. Required fields are marked *

We accept paid guest Posting on our Site : Guest Post Chat with Us On Skype