开发者

Newline characters not showing up

I have a form which escaped the input in PHP in a pretty standard way using this function:

mysql_real_escape_string( string )

But when I pull those contents out of the database, for some re开发者_开发百科ason, the spaces are no longer showing, and the text gets displayed as one big block. This page has the example of it in the hike description area: http://www.comehike.com/hikes/scheduled_hike.php?hike_id=131

Does anyone know why this is happening and how to prevent this? Is this a bug or normal behavior?


you have to learn HTML basics.

linebreaks intended not to be rendered in HTML.
To make it visible, you have to replace them with some HTML tag.


This is normal behavior - the "spaces" you are referring to are considered whitespace. You can read about how whitespace behaves in HTML here.

You have four basic options:

  1. Replace the line breaks with HTML line breaks at run-time using PHP's nl2br function (easy... if you do this, also wrap the whole description in a <p> tag)
  2. Wrap the description in <pre> tags (easy but not recommended as it is not semantically correct and will probably cause unintended styling headaches)
  3. Parse your description at run-time into actual paragraphs, wrapped in HTML <p> tags
  4. Compose your textual content with HTML markup in the first place so that it gets stored in the database that way (this is how most content management systems work)
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜