views:

329

answers:

2

How can I show these characters on a webpage?

A: 

Can you not do the following...

<?php
echo "&#92;n"."\n";
echo "&#92;0"."\n";
echo "&#92;t"."\n";
echo "&#92;x0B"."\n";
echo "&#92;r"."\n";
?>

Expected Result:

\n
\0
\t
\x0B
\r

and that should just print to screen, since &#92; is the reference for a \ on web pages.

EDIT:

Looks like StackOverflow auto-changes &#92; to a \ when not marked as code!

Urda
+1  A: 
// An example to replace all newlines with their character equivalent
$value = preg_replace('/[\r\n]+/', '\n', $value);
echo htmlentities($value);
Yada