Issue while reading string value from db and print in html page
I have an issue while reading the data(String) from database and prin开发者_运维问答t in html page.
Example: I stored string value "hello <--extra spaces here--> world" in db and i tried to get and print in html page it displays like "hello world" i hope it is an issue in html side can any one suggest regarding this issue.
Thanks in advance
just apply
white-space: pre;
attribute and print the value
for example:
<html>
<head>
<style type="text/css">
p
{
white-space:pre;
}
</style>
</head>
<body>
<p>
hello world
</p>
</body>
</html>
Of course, HTML wouldn't take extra spaces into account.
<pre>Hello World</pre>
Or
Hello<pre> </pre>World
Or
Hello World
will work.
You might like to save the value as the first option, in the database. In this way, you don't need to worry about any external attribute, I mean whether white-space
is set or not. The latter two would work, but not a good idea.
When displaying output to the browser, extraneous whitespace is stripped. You'll have to convert each space to in order to have it show in the browser. Alternatively, you can wrap the content in <pre> tags to preserve the spacing.
精彩评论