Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Taking a text field input and formatting into HTML

Posted on 2003-11-10
5
Medium Priority
?
234 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 120 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
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 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 …

705 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