el Dude
el Dude

Reputation: 5183

Preserving linebreaks in the begginning of textarea

Here again with new problem

$a='
1
2
3
';

in textarea it displayed without the first new line.

<?php echo'<textarea>',$a,'</textarea>'; />

like this

----------------
1
2
3
----------------

but it should be like this?

----------------

1
2
3
----------------

PS sorry for my English =)

Upvotes: 3

Views: 248

Answers (2)

jimcavoli
jimcavoli

Reputation: 854

You need to introduce a character the browser will render between lines, as an HTML parser will ignore normal whitespace characters. Namely: put a break (literally "<br>") tag between things you want on separate lines.

Upvotes: 0

ErikM
ErikM

Reputation: 70

Use the HTML decimal or hexadecimal code for carriage return instead of a space.

<textarea>
&#x0D;
1
2
3
</textarea>

Upvotes: 3

Related Questions