[SOLVED] Keeping a text areas formatting...

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
jonas
Forum Commoner
Posts: 96
Joined: Sun May 23, 2004 9:25 pm

[SOLVED] Keeping a text areas formatting...

Post by jonas »

Say I have a text area that users can type in and they want to format it with spaces and such.

Well when I insert it into the DB, it strips the spaces and the formatting.

I'm sure there is an easy fix for this, but I don't know what it is.

Any suggestions? Thanks.
Last edited by jonas on Sat Jun 26, 2004 4:56 pm, edited 1 time in total.
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

Replace all /n with <br />'s and all spaces with &nbsp; or tabs.
jonas
Forum Commoner
Posts: 96
Joined: Sun May 23, 2004 9:25 pm

Post by jonas »

I don't follow entirely what you mean. Obviously check the text area for spaces and replace with &nbsp; but how?
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

Code: Select all

$text = str_replace(" ","&nbsp;",$_POST['text']);
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you'll have to quote lil's post to get the text.. the site decided to hide it.. :)
Leedsoft Solutions
Forum Newbie
Posts: 11
Joined: Sat Jun 12, 2004 1:17 pm

Post by Leedsoft Solutions »

jonas
Forum Commoner
Posts: 96
Joined: Sun May 23, 2004 9:25 pm

Post by jonas »

It's not working for me ... I dont think.

I put it in my code but when I submit a text area, first off now if its too big it says server not found (like the page wont even load) and secondly if i do a smaller submission, the text area's variable in the DB is all empty.
It's almost as if it turns the entire string to spaces but that cannot be because if I try to submit the same thing again, my submission checker for the same code kicks in and gives an error.

Code: Select all

if ($Submit == "Submit Code")&#123;
$code_text = strip_tags($code_text);
$sql_username_result = mysql_query("SELECT * from game_codes WHERE memberID='$memberID' AND code_title='$code_title'");
if (empty($code_title))&#123;
	$error = 1;
	$nocodetitle = "You did not fill out a code title.";
&#125;
if (empty($code_text))&#123;
	$error = 1;
	$nocodetext = "You did not fill out a code description.";
&#125; else &#123;
	$code_text = str_replace(" ","nbsp;",$code_text);
&#125;
PS: The nbsp code on my actual server does have a & but i took it out here to show you.
jonas
Forum Commoner
Posts: 96
Joined: Sun May 23, 2004 9:25 pm

Post by jonas »

Solved, thanks for your help guys.
Post Reply