There is a goal to add poems to the database using PHP. The question is how to preserve the original text formatting in the database or how to get the data from the database in the original format using PHP?

Currently in block

I sit behind bars in a wet dungeon. Fed up in captivity, the eagle is young, My sad friend, flapping his wing, Blood food pecks under the window,

I need it like this

I sit behind bars in a wet dungeon.
The young eagle fed up in captivity
My sad friend, flapping his wing,
Bloody food pecks under the window

  • Add with html markup and your problem will be solved. - Dan the Hat
  • one
    nl2br() Maybe this will help you - ArchDemon
  • @DantheHat is not as simple as it would seem. Poems can send ordinary users. Therefore, manually put the tags at the end of the lines does not roll. - SNuSNuMR1996
  • @ SNuSNuMR1996 well then, in truth, process the nl2br() th line before being thrown into the base. Well, or as an option - fasten to the text field some редактор that rewrites on the machine in html . - Dan the Hat

2 answers 2

Use: nl2br - Inserts HTML line break before each line break

  • Thank you Earned as needed! - SNuSNuMR1996
  1. Tell the browser not to format the verse. Wrap a <pre> tag or set white-space: pre; for the style (css) of the element in which the poem is displayed.

  2. Alternatively, you can use nl2br .

But then this is not formatted.

 Дверь. На двери - "Нельзя без доклада" Под Марксом, в кресло вкресленный, с высоким окладом, высок и гладок, сидит облеченный ответственный. ... -- Владимир Маяковский 
  1. Most writing a smart parser / formatter, but it can be difficult.