1

I was wondering if it is possible to make control characters in a string visible.

    $mystring = "Test\n";
    echo $mystring;

This will output Test but i don't want PHP to translate \n it should just output Test\n (For debugging purposes). Is this possible?

Black
  • 18,150
  • 39
  • 158
  • 271

2 Answers2

3

Put it between single quotes:

$mystring = 'Test\n';
echo $mystring; //Returns Test\n
Daan
  • 12,099
  • 6
  • 34
  • 51
2

Use escape sequence with double quotes " or just enclose string in single quotes '.

$mystring = "Test\\n";
echo $mystring;

$mystring = 'Test\n';
echo $mystring;

https://eval.in/559063

Also check the difference and use of quotes : What is the difference between single-quoted and double-quoted strings in PHP?

Community
  • 1
  • 1
Niklesh Raut
  • 34,013
  • 16
  • 75
  • 109