Enters turn into spaces

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
Rob
Forum Commoner
Posts: 33
Joined: Fri Oct 03, 2003 3:18 pm

Enters turn into spaces

Post by Rob »

Whenever a user enters a story and sends to the server, anywhere they hit enter (to make a new line...) it turns into a space instead..what do I do?
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

Post by qads »

Code: Select all

<?php
$blockoftext = nl2br($_POST['blockoftext']);
?>
make sure you use it before inserting the record into the database.
User avatar
Rob
Forum Commoner
Posts: 33
Joined: Fri Oct 03, 2003 3:18 pm

Post by Rob »

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

Post by twigletmac »

Don't use nl2br() before putting data into the database, because then when you come to edit the record you'll get a bunch of unwanted <br />'s, instead only use nl2br() when you display the story and keep it unchanged in the database.

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

Post by twigletmac »

P.S. The enters are being changed into new line characters (\n on *nix, \r\n on Windows and \r, IIRC, on Macs).

Mac
Post Reply