Is there an equivalent to string literals in C # in PHP?

I know that I can create a literal string literal in C # using the @ symbol. For example, ordinary

String path = "C:\\MyDocs\\myText.txt"; 

can also be rewritten as

 String path = @"C:\MyDocs\myText.txt"; 

Thus, the string literal is not cluttered with escape characters and makes it more readable.

What I would like to know is whether PHP has an equivalent or do I need to manually delete the line?

+6
string php
source share
2 answers
 $path = 'C:\MyDocs\myText.txt'; 

" double quotes allow all kinds of special sequences of characters, ' single quotes are verbatim (there are only some small print about escaping ' and escape \ escaping).

+5
source share

Even single quotes in PHP need to avoid at least literal single quotes and literal backslashes :

 $str = 'Single quotes won\'t help me \ avoid escapes or save a tree'; 

The only unanalyzable solution for PHP is to use nowdocs . This requires the use of PHP 5.3.

 $str = <<<'EOD' I mustn't quote verbatim text \ maybe in the version next EOD; 
+3
source share

All Articles