Sankar Smith
Sankar Smith

Reputation: 356

Print html code in text area

Here I need to display text with break line but I simply display the html code inside the text area. Here is my code

<?php
$msg.="From :";
$msg.="<br/>";
$msg.="To :";
$msg.="Date :";
print_r($msg);
?>
<textarea><?php print_r($msg);?></textarea>

I need to print html executed code in text area. Thank you in advance.

Upvotes: 0

Views: 904

Answers (3)

Dalin Huang
Dalin Huang

Reputation: 11342

HTML way to fix it, use ASCII characters &#013; &#010;.

Carriage return &#013;

Line feed &#010; (HTML entity: &NewLine;)

REF: http://www.theasciicode.com.ar/ascii-control-characters/carriage-return-ascii-code-13.html

<textarea cols='60' rows='8'>This is line1&#13;&#10;This is line2</textarea>

Upvotes: 4

Kalacia
Kalacia

Reputation: 118

You could try something like:

echo '<textarea>'.print_r($msg).'</textarea>';

Upvotes: 0

Naqash Malik
Naqash Malik

Reputation: 1816

Just replace your code from:

<textarea><?php print_r($msg);?></textarea>

to:

<textarea><?php echo $msg;?></textarea>

Upvotes: 0

Related Questions