So, I have a bunch of code that I'm pulling from a column in MySQL. This code includes hidden characters, such as "\t" and "\n".
I'm trying to get that raw code to display in a DIV. I was hoping to actually show the hidden characters. I have the following so far, without much luck:
<?php
// Simple example: replace all newlines with their character equivalent
$value = str_replace("\n", '\n', $value);
echo htmlentities($value);
Any ideas?
Hmm, that should be working... Maybe the newline characters are actually carriage returns? In which case, something like this would be flexible:
Add shlashes and preserve newline ;)
if you have
the result is
for the html output line.
Please note that in PHP "string" and 'string' are actually the same thing.
htmlentities() just converts quote characters and other special characters to their HTML entity equivalent. See this page
Escape your slashes and (optionally) enclose the code that you want explicity shown in 'pre' tags. The pre tags are not necessary but can help readability.
Here is the code I tested:
If you truly want to see everything, use for example this hex dump function. It's good for finding weird UTF-8 (UTF-8 space is not same as ASCII space character and so on) or BOM stuff etc.
It outputs like this
You can try the
­
For example : "" it is between the "