Solved

Taking a text field input and formatting into HTML

Posted on 2003-11-10
5
226 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
CA single sign on 2 73
unset shopping cart session 15 29
Update from TABLE-A to TABLE-B 5 38
PHP get array item with custom id 4 21
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…
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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…

911 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

17 Experts available now in Live!

Get 1:1 Help Now