Solved

Taking a text field input and formatting into HTML

Posted on 2003-11-10
5
222 Views
Last Modified: 2006-11-17
I have a script on my site where a user can upload instructions, complete with pictures and drawings, for others to view and use. It works great with the exception of formatting. When the user hits return in the text field they are formatting it as they see it, but the script does not insert any HTML. When the same piece of data is retrieved from the database (postgresql) the browser renders it as if it was all written on one line. My problem is getting the script to be "smart enough" to format the text correctly and make the end result pretty for other users. Is this possible using strictly php, or will I need to use javascript as well?

_________________
Rex Burgess
0
Comment
Question by:rexburgess
5 Comments
 
LVL 5

Expert Comment

by:arjanh
ID: 9720459
In PHP you can search and replace the newlines with '<BR>':

$html_text = preg_replace( /\n/, "<BR>", $submitted_text );
0
 

Expert Comment

by:joffley
ID: 9720742
the HTML <pre> tag may help.
0
 

Expert Comment

by:FNajjar
ID: 9722817
You can use nl2br function.
this will fix the whole problem.
0
 

Author Comment

by:rexburgess
ID: 9723221
how is the nl2br function used?

_______________
rex burgess
0
 

Accepted Solution

by:
FNajjar earned 30 total points
ID: 9723513

$var = nl2br("$string");
echo "$var";

It  will read all the spaces break points in the text area and put as it is.
go to www.php.net and search for nl2br or nl2br()

I use it all the time.   :)
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

758 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

16 Experts available now in Live!

Get 1:1 Help Now