Solved

putting preformatted text in mysql

Posted on 2004-10-04
16
298 Views
Last Modified: 2013-12-12
I have a form field that collects an artists biographical information. This then appears on the artists web page. Often the text has certain bolded areas, underlinings, etc.

I would like the user filling out the form to be able to copy and paste there bio info into the form field and retain the formatting when it is stored in the db and output to the artist's page.

However on the artists website page, the artist bio needs to fit into a space about 190 pixels wide.

Basically I would like the text to retain the formatting (any bold text, underlines, line breaks,etc) that the user pastes into the form field and also conform to the width dimension listed above - to keep the look of the artist page consistent.

The less code the better if possible...thanks
0
Comment
Question by:dblacker
  • 7
  • 6
  • 2
  • +1
16 Comments
 
LVL 48

Expert Comment

by:hernst42
ID: 12220863
You can suround the text with a div -tag:

<div style="width:190px;"><?=$text?></div>

This puts the text into 190pixel column
0
 
LVL 12

Expert Comment

by:minichicken
ID: 12221259
Are you looking for a rich text box, so you can save the text in HTML format in the DB?
0
 

Author Comment

by:dblacker
ID: 12221377
maybe...just looking for a way for the user to copy and paste preformatted text - have it saved as such in db - then appear on artist page with all preformatting...
0
 
LVL 12

Expert Comment

by:minichicken
ID: 12221378
If you are looking for a WYSIWYG HTML editor or text box.
You should take a look at http://www.dynarch.com/projects/htmlarea/ (I think it' free) and http://www.blueshoes.org/en/javascript/editor/ (don't think it's free)

What you can do with this WYSIWYG editor is that, the user can preformat his/her text in that text box. When you posts the values to your PHP page to be inserted into the DB, that passed value will be the HTML code (for bold, italics text, etc...).

If you are passing HTML code with HTML special characters to the DB, remember to use the htmlspecialchars(); function to prevent any output errors while retrieving the text from the DB.

regards

j311y :)
0
 

Author Comment

by:dblacker
ID: 12221408
thanks for the links - that would work but is an added step i would prefer to avoid. the average user may not be that web savvy and i would, if possible, just make them copy and paste...
0
 
LVL 12

Expert Comment

by:minichicken
ID: 12221428
I think the one from http://www.dynarch.com/projects/htmlarea/ will be useful if you want the user to copy and paste HTML formated text. When you do a copy and paste, it will paste the exact format (bold, italics, etc....) except for the CSS style.
0
 
LVL 12

Accepted Solution

by:
minichicken earned 400 total points
ID: 12221452
I've tried it before, it not that difficult to integrate, and ofcoz you can customize it according to your needs.
Maybe you should go try out the demo at http://www.dynarch.com/demos/htmlarea/examples/core.html and do a copy and paste to check if its the result that you want.
0
 

Author Comment

by:dblacker
ID: 12222112
This very text box in which i am writing now will format the line breaks that i create when i hit the enter. Knowing how to do this would be a good start...
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 12

Expert Comment

by:minichicken
ID: 12222355
Good start.... anyways hope you did find the links to the textbox and the demo useful for you or added some value to your question :)
0
 

Author Comment

by:dblacker
ID: 12222428
but i don't know how to achieve the results that this textarea box does...i was saying if someone knew how to get the line breaks when you hit enter i would really like to know that?




like this line is way down here -


0
 

Author Comment

by:dblacker
ID: 12222502
wait got the line break thing --> $artist_bio =  nl2br($artist_bio);
0
 
LVL 12

Expert Comment

by:minichicken
ID: 12224374
Hi dblacker

No offence or anything, may I know why you dont want to just incorporate HTMLAREA WYSISYG from http://www.dynarch.com and re-invent the wheel? Is that not what you looking for?

regards
0
 

Author Comment

by:dblacker
ID: 12226531
well it's pretty good but it seems it's only compatable with explorer 5.5 and above which might preclude some people. I was trying to find out another way to design the input form so that I could be more specific with the format and just get around this whole thing all together .

As for dynarch does it need to be installed on each persons computer that fills out the form or is the formatting done online - the latter case would be better becuase i'm trying to avoid the user having to download the software - install it - etc.

I think it is a good suggestion ijust don't know if i'm complicating things...
0
 
LVL 12

Expert Comment

by:minichicken
ID: 12226726
The user dont need to install that HTMLAREA from dynarch on their machine, you only need to have it on your web server, it works just like a normal textbox just that it accepts preformatted HTML code. So the user does not require to download, he/she can do the formatting online in that rich text box, just like you wanted. It WYSIWYG which makes it very user friendly.

Download it at: http://prdownloads.sourceforge.net/itools-htmlarea/HTMLArea-3.0-rc1.zip?download

I don't know if it works with older browser version, as I couldnt test that, I did however test it on Netscape 7 and IE6 and it works fine.

I really think it a very good tool, and can save you alot of time, if I understand your question corrrectly.

regards

j311y
0
 
LVL 15

Assisted Solution

by:nicholassolutions
nicholassolutions earned 100 total points
ID: 12227918
Try this: store the text input by the user as a string in the database (including all line breaks as-is). When you pull the text out, surround it by <pre> tags:

<pre>
user inputted text
</pre>

One word of caution: This allows users to do some potentially VERY annoying stuff, so you should try to do some checks on the input text before just blindly putting it in the db. For example, check to make sure the input string is shorter than some threshold value to make sure they did not dump in 1MB of text. More importantly, make sure they did not enter 100 line breaks in a row...It could be a real pain in the neck if someone does something like this....







....except 100 times. And of course, make sure you strip out HTML...a lot of this has to do with how much you will trust your users, but it's always a good idea NOT to and then work from there, because there are a lot of jerks out there ;)

Cheers
0
 
LVL 15

Expert Comment

by:nicholassolutions
ID: 12227984
....Just to clarify, my solution will not retain bold/underlining, but it will retain layout. One thing that a lot of online forums do to allow people to do formatting is to make custom 'tags' that get translated to html by your script. For example, you might telll users, if you want bold text, do this

[bold] bold text [plain] normal text

and then translate every [bold] into a </b> tag or whatever. Unless you do something like minichicken is suggesting, the user will have to do at least some work to translate something from rich text to HTML.

Cheers
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now