tags:

views:

24

answers:

2

Hello,

Is there a way one can let a user manipulate text he/she may be typing via PHP? For example, the user may be able to make the text he/she has typed bold or even italicized. One can assume, that I am trying to get similar effects of this website. Is there a way to do this in PHP? I am trying to do this because once the user hits 'submit' after typing the textual information, the information will then be saved into a MySQL table. From where, I will at a later time, try to display the information. Therefore, it would be easy to retrieve text as the user had typed it (bold or even italicized). How does it work?

Thank you.

+1  A: 

StackOverflow uses the Markdown language. There's a PHP implementation of it here: http://michelf.com/projects/php-markdown/ and a JavaScript implementation here: http://attacklab.net/showdown/ or you can use the WYSIWYG control StackOverflow's editing is based on: http://wmd-editor.com/

Basically it stores italics and bold (and other formatting like lists) as simple text with special formatting: *italics* **bold** so that you can store that plain text in your database. Then it formats that before displaying it.

(here's the actual markdown project: http://daringfireball.net/projects/markdown/)

NickAldwin
Also take a look at this question: http://stackoverflow.com/questions/1617776/php-mysql-is-there-a-way-to-store-text-in-rich-text-format-in-mysql-table
NickAldwin
@ Nick - Hmm..the wmd-editor makes life a lot easier. Thank you.
Newbie_25
@newbie-25 Glad to hear it.
NickAldwin
+1  A: 

SQL just saves text - if you want to support formatting, you can either allow HTML entities & mind this when you display such text via PHP or look at other markup approaches like Markdown. Mind that allowing HTML entities risks javascript injection attacks.

OMG Ponies