What Are the Special Characters You Need to Escape in Single-Quoted Stings?
There are two special characters you need to escape in a single-quote string: the single quote (') and the back slash (\). Here is a PHP script example of single-quoted strings:
<?php
echo 'Hello world!';
echo 'It\'s Friday!';
echo '\\ represents an operator.';
?>
This script will print:
Hello world!It's Friday!\ represents an operator.
Can You Specify the "new line" Character in Single-Quoted Strings?
You can not specify the "new line" character in a single-quoted string. If you don't believe, try this script:
<?php
echo '\n will not work in single quoted strings.';
?>
This script will print:
\n will not work in single quoted strings.
How Many Escape Sequences Are Recognized in Single-Quoted Strings?
There are 2 escape sequences you can use in single-quoted strings:
- \\ - Represents the back slash character.
- \' - Represents the single quote character.
Read More »
Tags:
infosys,
Lnt,
php
