开发者

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&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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 &nbsp; in order to have it show in the browser. Alternatively, you can wrap the content in <pre> tags to preserve the spacing.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜