I am printing a article with spaces inside the article.
Text inside article has HTML tags also,so i am using htmlentities before echo.
But problem is that display does’t show spaces on the browser.
What is the problem with these commands?
Can someone please suggest me a better option?
DB update command:
mysql_real_escape_string($text, $db)
Article display command:
echo nl2br(htmlentities($row_page['text']));
Example: displayed text is pretty ugly
Real text and i am expecting same:
dbus-1/ libcom_err.so.2@ libglib-2.0.so.0@ liblvm2cmd.so.2.02* libpopt.so.0.0.0*
device-mapper/ libcom_err.so.2.1* libglib-2.0.so.0.2200.5* libm-2.12.so* libproc-3.2.8.so*
firmware/ libcrypt-2.12.so* libgmodule-2.0.so.0@
HTML collapses all whitespace (spaces or newlines or tabs) into a single space. You can work around it by replacing
' 'with' ', for example:But even cleaner is to just have the browser use
preformatted whitespace:Or alternatively use CSS for a bit of extra flexibility:
Pre formatted whitespace has some drawbacks, for example you can’t have any newlines or indentation in your HTML file when you’re using
pre, because the browser will render them. But when you really need to control how something is rendered it’s the best choice.