Computer >> Computer tutorials >  >> Programming >> PHP

How do you make a string in PHP with a backslash in it?


When the backslash \ does not escape the terminating quote of the string or even create a valid escape sequence (in double quoted strings), then the below code can be used to produce one backslash −

Example

$string = 'abc\def';
print($string);

Output

This will produce the following output −

abc\def

Example

$string = "abc\\def";
print($string);

Output

This will produce the following output −

abc\def