Strings - Manual - PHP

Single quoted

The simplest way to specify a string is to enclose it in single quotes (the character ').

To specify a literal single quote, escape it with a backslash (\). To specify a literal backslash, double it (\\). All other instances of backslash will be treated as a literal backslash: this means that the other escape sequences you might be used to, such as \r or \n, will be output literally as specified rather than having any special meaning.

Note: Unlike the double-quoted and heredoc syntaxes, variables and escape sequences for special characters will not be expanded when they occur in single quoted strings.

Example #1 Syntax Variants

<?phpecho 'this is a simple string', PHP_EOL;echo 'You can also have embedded newlines instrings this way as it isokay to do', PHP_EOL;// Outputs: Arnold once said: "I'll be back"echo 'Arnold once said: "I\'ll be back"', PHP_EOL;// Outputs: You deleted C:\*.*?echo 'You deleted C:\\*.*?', PHP_EOL;// Outputs: You deleted C:\*.*?echo 'You deleted C:\*.*?', PHP_EOL;// Outputs: This will not expand: \n a newlineecho 'This will not expand: \n a newline', PHP_EOL;// Outputs: Variables do not $expand $eitherecho 'Variables do not $expand $either', PHP_EOL;?>

Tag » What Is A String In Php