Solved

Taking a text field input and formatting into HTML

Posted on 2003-11-10
5
232 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
This article discusses four methods for overlaying images in a container on a web page
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

710 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