html special characters???

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Skywalker
Forum Contributor
Posts: 117
Joined: Thu Aug 29, 2002 3:33 am
Location: The Netherlands

html special characters???

Post by Skywalker »

I am having some kind of guestbook, but when you are entering a text in an textarea and you give a enter je get an empty row in the textarea, but when you write it then to the database, the enter isn't enylonger ther

I just plases all of the text behind just as one blok not with seperated enters. How can I do this? A friend of mine told me to use special html characters, but how can I put them automatic in ther?

Greathings Skywalker
evilcoder
Forum Contributor
Posts: 345
Joined: Tue Dec 17, 2002 5:37 am
Location: Sydney, Australia

Post by evilcoder »

When your putting the message from the database into the page, assign it a variable then use this:

// Adds brake lines to html
$variable = nl2br( $variable );
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Use nl2br() when you output the data. The newlines are not being lost when they go into the database, they are instead being stored as new line characters (\n), by using nl2br() on the text before you output it to the page you get an HTML line break (<br />) next to each newline character. This means that the text will look on the page as it does in the text area.

Mac
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

I appear to be getting slow in my old age :roll: .

Mac
evilcoder
Forum Contributor
Posts: 345
Joined: Tue Dec 17, 2002 5:37 am
Location: Sydney, Australia

Post by evilcoder »

hahaha, nah... Hey twig, are you good with Classes, Functions and Stupid Session that wont be cREATED I WORKED AGES ON THIS!!! LOL... sorry got a bit fired up?
Post Reply