我有一個HTML表單頁面(test.php),有2個textareas和一個提交按鈕。我不是每次都要複製要格式化和硬編碼的源代碼,而是創建了第一個textarea,以便我可以將待清理的代碼複製到其中。然後在按下提交按鈕後,表單將發佈到同一頁面,並在第二個文本區域中顯示已更新的源代碼。 顯示這個更加完整的源代碼是問題。通過HTML tidy傳遞以下代碼並嘗試在textarea中顯示輸出,從而中斷輸出顯示。我的意思是,如果你注意到,我在下面的html代碼中有</textarea>
。只要Tidy遇到它,它就會關閉textarea,並將源代碼的其餘部分解析爲HTML文檔的一部分,從而打破了我的整個HTML表單頁面(test.php)。PHP Tidy:Breaks textareas
示例源代碼,我傳遞給HTML精簡:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Hi</title>
<link href="css/styles.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="wrapper">
<h1 data-title="Hi"> <a href="<?php echo $_SERVER['PHP_SELF']; ?>"> Hi </a> </h1>
<form name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<textarea name="comments" id="comments" cols="150" rows="15"><?php echo (isset($_POST['comments']) ? $_POST['comments'] : ''); ?></textarea>
<br>
<input type="submit" name="sbt_process" id="sbt_process" value="Submit">
</form>
<textarea name="css" id="css" cols="150" rows="18"><?php echo (isset($text) ? $text : ''); ?></textarea>
</div><!-- #wrapper -->
</body>
</html>
HTML精簡PARAMTERS:
$params_body = array(
'break-before-br' => 'no',
'clean' => 'clean',
'doctype' => 'strict',
'drop-empty-paras' => 'yes',
'drop-font-tags' => 'yes',
'force-output' => 'yes',
'indent' => TRUE, //'yes',
'indent-attributes' => FALSE,
'indent-spaces' => 4,
'input-encoding' => 'utf8',
'join-styles' => 'yes',
'literal-attributes' => 'yes', //This option specifies if Tidy should ensure that whitespace characters within attribute values are passed through unchanged.
'logical-emphasis' => 'yes',
'lower-literals' => 'yes',
'merge-divs' => 'no',
'merge-spans' => 'yes',
'output-encoding' => 'ascii',
'output-xhtml' => 'yes',
//'output-xml' => true,
'output-bom' => 'no',
'preserve-entities' => 'yes',
'quiet' => 'yes',
'quote-ampersand' => 'yes',
'quote-marks' => 'no',
'quote-nbsp' => TRUE,
'show-body-only' => FALSE,
'show-errors' => 0,
'show-warnings' => 0,
'sort-attributes' => 'alpha',
'vertical-space' => TRUE, //'yes',
'wrap' => 0, //This option specifies the right margin Tidy uses for line wrapping. Tidy tries to wrap lines so that they do not exceed this length. Set wrap to zero if you want to disable line wrapping.
'wrap-attributes' => FALSE,
'tab-size' => 20, //This option specifies the number of columns that Tidy uses between successive tab stops. It is used to map tabs to spaces when reading the input. Tidy never outputs tabs.
'wrap-php' => 0,
'wrap-script-literals' => TRUE,
'escape-cdata' => TRUE,
'indent-cdata' => TRUE,
'numeric-entities' => FALSE,
'fix-uri' => FALSE,
'markup' => TRUE
);
我一直在用PHP整齊的不同PARAMS瞎搞,但它沒用。我甚至試圖將它輸出爲XML,但這沒有幫助。我如何使Tidy在第二個textarea中正確顯示已清理的源代碼而不破壞/解析我正在嘗試清理的源代碼的</textarea>
標記?