Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 236
  • Last Modified:

Taking a text field input and formatting into HTML

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
rexburgess
Asked:
rexburgess
1 Solution
 
arjanhCommented:
In PHP you can search and replace the newlines with '<BR>':

$html_text = preg_replace( /\n/, "<BR>", $submitted_text );
0
 
joffleyCommented:
the HTML <pre> tag may help.
0
 
FNajjarCommented:
You can use nl2br function.
this will fix the whole problem.
0
 
rexburgessAuthor Commented:
how is the nl2br function used?

_______________
rex burgess
0
 
FNajjarCommented:

$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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now