Make a String in PHP with a Backslash



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

 Live Demo

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

Output

This will produce the following output −

abc\def

Example

 Live Demo

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

Output

This will produce the following output −

abc\def
Updated on: 2020-04-09T10:35:14+05:30

371 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements