2013-07-22 34 views
1

我使用PHP來填補一個textarea:轉換html標記中的textarea,以豐富的文字

<textarea text-input" id="Desc" rows="15" wrap="soft" name="Desc"><?php echo $Desc; ?></textarea> 

但是textarea裏顯示它的HTML標籤,我不想要。

<b>Analog And Digital System</b><br /> 
<b>Analog System:</b><br /> 
A string tied to a doorknob would be an analog system. They have a value that changes steadily over time and can have any one of an infinite set of values in a range. If you put a measuring stick or ruler at a specific point along the string, you can measure the string's value every so many seconds at that point. When you watch it move, you will see it moves constantly. It doesn't instantly jump up and down the ruler. <br /> 
<br /> 
<b>Digital System:</b><br /> 
A digital system would be to flick the light switch on and off. There's no 'in between' values, unlike our string. If the switch you are using is not a dimmer switch, then the light is either on, or off. In this case, the transmitter is the light bulb, the media is the air, and the receiver is your eye. This would be a digital system.<br /> 

基本上就是我想要做的是轉換<b>標籤使內容大膽<br>標籤新線。

我想不使用任何編輯器。

回答

1

沒有辦法做HTML裏面的textarea,你將不得不使用Ant編輯格式,但如果你想顯示其在格則設置屬性CONTENTEDITABLE =「true」會做的伎倆

更多引用here(已問及計算器)

1

你應該使用基於所見即所得 HTML編輯器,如tinymceCKEditor用於此目的的JavaScript。

否則,HTML代碼將保持原樣(純文本)。

但是,如果您使用編輯器,用戶將能夠編輯內容並將內容轉換爲使用JavaScript的富文本格式(而編譯器會爲您神奇地做到這一點)。

所見即所得 =你所看到的就是你得到

0

如果你想只顯示HTML輸出,然後用div標籤相反,你應該使用的代碼在這裏Converting <br /> into a new line for use in a text area

<? 
    $text = "Hello <br /> Hello again <br> Hello again again <br/> Goodbye <BR>"; 
    $breaks = array("<br />","<br>","<br/>"); 
    $text = str_ireplace($breaks, "\r\n", $text); 
?> 
<textarea><? echo $text; ?></textarea>