2012-07-29 45 views
0

我正在使用Javascript來產生HTML編碼的textarea,這工作正常,然後我存儲到SQL數據庫。還行吧。但是當我想輸出這個回textarea再次被編輯時,php-tidy將關閉的textarea標籤移動到內容之前,所以實際上將內容放在textarea標籤之後。這隻會發生在內容與HTML標籤格式化,但這些都需要產生格式我需要產生HTML格式的電子郵件等當我禁用PHP整潔所有工作好,只是HTML代碼是一個完整的混亂phptidy textarea與HTML格式文本

如果無論如何,任何人都可以通過PHP-tidy來忽略代碼的某些部分,或者免除textarea被PHP-tidy解析,這會很棒。

的代碼,我簡單

//從數據庫內容

$message = stripslashes($database['message']); 
$buffer = "<textarea id=\"elm1\" name=\"message\" cols=\"70\" rows=\"20\">$message</textarea>"; 

$config = array('indent' => TRUE, 
      'doctype' => "strict", 
      'output-xhtml' => TRUE, 
      'wrap' => 300); 
$tidy = tidy_parse_string($buffer, $config); 
$tidy->cleanRepair(); 
echo $tidy; 

如果消息沒有HTML內容的格式是確定

PHP整潔禁用它出來一樣,是格式不是很好,但工作方式我期望

<textarea id="elm1" name="Message" cols="70" rows="20"><p>this is a full html email.</p> 
<p>little formatting </p> 
<p><span style="color: #ff0000;">different colour text</span></p> 
<p>and normal</p></textarea> 

php tidy enabl ED

<textarea id="elm1" name="Message" cols="70" rows="20"> 
</textarea> 
    <p> 
     this is a full html email. 
    </p> 
    <p> 
     little formatting 
    </p> 
    <p> 

     <span style="color: #ff0000;">different colour text</span> 
    </p> 
    <p> 
     and normal 
    </p> 

我想PHP-整潔啓用,但仍然有結果我想到

感謝

Vip32

+0

沒有辦法幫你沒有代碼,對不起。 – arkascha 2012-07-29 14:40:35

回答

0
$message = stripslashes($database['message']); 
// DO the tidy before interpolating with 
// the html of your form element 
$config = array('indent' => TRUE, 
      'doctype' => "strict", 
      'output-xhtml' => TRUE, 
      'wrap' => 300); 

$tidy = tidy_parse_string($message, $config); 
$tidy->cleanRepair(); 

// now insert it into the correct place 

$buffer = "<textarea id=\"elm1\" name=\"message\" cols=\"70\" rows=\"20\">$tidy</textarea>"; 

echo $buffer; 

你只是組裝的東西在錯誤的順序,我認爲。

未經檢驗