dcsimg
www.webdeveloper.com
Results 1 to 5 of 5

Thread: a script to convert text with formatting into html?

  1. #1
    Join Date
    Jul 2004
    Posts
    2

    a script to convert text with formatting into html?

    Does anybody know how i can convert text with basic formating (Line breaks, bullets, bold, italic & underline) from a text box into HTML? The same way the text box in the 'reply' form on this site does - you type something with line breaks or whatever and it gets converted to HTML. This is for a PHP section of a site where users can enter info via a form to be stored in a database and displayed on another section of the site. The people entering the info dont know HTML, so i want to be able to let them just type and it will appear as they typed it when it is retrieved from the database, i thought if it stored HTML tags too for the formatting this would take care of it, but if anyone can suggest a better way i'd be happy to hear that too

    Thanks
    Last edited by Kingskin; 07-20-2004 at 04:06 PM.

  2. #2
    Join Date
    Jun 2004
    Location
    Between keyboard and chair
    Posts
    77
    The function nl2br() makes any \n into br tag, which will make any line break in your form into an html break if applied to form input.

    One of my friends put some formatting tools in the comments part of his blog where you can highlight text in the form and use javascript buttons to wrap it in the appropriate html tags. Of course, inexperienced users could easily mess that up. I'm sure this site (VBthread based?) uses a rather detailed script to accomplish formatting.

  3. #3
    Join Date
    Jul 2004
    Posts
    2
    Originally posted by iamlucky13
    The function nl2br() makes any \n into br tag, which will make any line break in your form into an html break if applied to form input.

    One of my friends put some formatting tools in the comments part of his blog where you can highlight text in the form and use javascript buttons to wrap it in the appropriate html tags. Of course, inexperienced users could easily mess that up. I'm sure this site (VBthread based?) uses a rather detailed script to accomplish formatting.
    Hi iamlucky13, thanks for your reply.

    Ill look into the function you suggest, thats one of the main formatting issues resolved

    Javascript buttons are a good idea too, im sure the ones used by VB such as the IMG and QUOTE buttons are pretty easy to get working. It'd certainly be more simple than using PHP for the lot, and theyre all moderators of my VBulletin site so theyre used to using them
    thanks again

  4. #4
    Join Date
    Jun 2004
    Location
    Between keyboard and chair
    Posts
    77
    No problem.

    I haven't looked at the html output for this page much, but I imagine it just uses client-side scripting to put in tags that are easy to look for with PHP. I mean, the I, B, URL, etc. wrapped in square brackets. Then the PHP would handle switching those out for the appropriate HTML tags. It seems like it would be a lot of processing on the server, but it simplifies the user's interface and also means you can still strip out potentially annoying or even dangerous html and php code from the form.

  5. #5
    Join Date
    Oct 2005
    Location
    California
    Posts
    603
    Test

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles