Mateus
Mateus

Reputation: 2668

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

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);

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

   ";

   }

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).

Upvotes: 2

Views: 8862

Answers (3)

rohit maurya
rohit maurya

Reputation: 21

As other have explained. i have some solution like below code. actually I created a div then I converted it as textarea then my php code.

its working for me properly please try it at once. I think you got your answer.

 <div style="height: 100px;overflow-y: scroll;text-rendering:     auto;overflow: auto;resize: vertical;">

 <?php echo nl2br($value['rt_master_conversation']); ?>

</div>

Upvotes: 0

Murtaza
Murtaza

Reputation: 3065

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.

Upvotes: 2

nimrodm
nimrodm

Reputation: 23789

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.

Upvotes: 1

Related Questions