Basic PHP Programming Question: Download Questions PDF
What Are the Special Characters You Need to Escape in Double-Quoted Stings?
Answers:
Answer #1There are two special characters you need to escape in a double-quote string: the double quote (") and the back slash (). Here is a PHP script example of double-quoted strings:
<?php
echo "Hello world!";
echo "Tom said: "Who's there?"";
echo " represents an operator.";
?>
This script will print:
Hello world!Tom said: "Who's there?" represents an operator.
<?php
echo "Hello world!";
echo "Tom said: "Who's there?"";
echo " represents an operator.";
?>
This script will print:
Hello world!Tom said: "Who's there?" represents an operator.
Answer #2print "Tom Said:\"Who's there?\"";
We need to escape \"(double quotes) by prefixing it with \ (backslash) like the above code
We need to escape \"(double quotes) by prefixing it with \ (backslash) like the above code
Download PHP Interview Questions And Answers
PDF
Previous Question | Next Question |
Can You Specify the "new line" Character in Single-Quoted Strings? | How Many Escape Sequences Are Recognized in Double-Quoted Strings in PHP? |