php – Enable <textarea> to display HTML content,such as bold,italic,color,img tags-ThrowExceptions

Exception or error:

I’ll try to be clear in the question,i need to display HTML content on a .Let me explain what i trying to do.

1-On my main file i have a which sends the text inserted to a mysql table.(OK)
2-After on the same page PHP execute a query and search for the rows containing an id inserted together with the message.(OK)
3-After the PHP found the rows with the same id i display these messages using the code bellow(the messages are displayed on a textarea):

while ($runrows = mysql_fetch_assoc($run_two)){

   $horario = $runrows['added'];
   $autor = $runrows['autor'];
   $mensagem = $runrows['mensagem'];
   $codigosender = $runrows['codigosender'];

   $testevar = htmlspecialchars($mensagem);

   <table width='500px;'>
   <tr><td width='75%'>$autor</td><td width='25%'>$horario</td></tr>
   <textarea name='displayMessages' style=' width:500px;' readonly>$testevar</textarea>



Now is my problem: If i insert on my sender the message ‘(bold tag)Mateus(bold tag)‘,when the PHP display on the textarea it doesn’t display the ‘Mateus’ in bold!So how can i enable the textarea to do so?(Basically i want to enable my textarea to work as this one i writing now).

How to solve:

HTML textarea will not have any styling for the value it contents.

if you wish to give styling you will need to use third party controls. like CKEditor, or freetext Box, otherwise you will need to create your own textarea.


As other have explained, you cannot style the contents of a TextArea element.

However, you can take the other route and make a standard div editable if you set its contentEditable property to true. This makes the div element behave similarly to a text area. Of course, to actually let the user change styles, you would have to add some external controls (buttons, bind keypress events, etc.) See a nice example at Joe Armstrong’s blog

But the easiest method is probably to just use CKEditor or similar package.

Leave a Reply

Your email address will not be published. Required fields are marked *