我有一个带有 2 个文本区域和一个提交按钮的 html 表单页面 (test.php)。我没有每次都复制我想要格式化和硬编码的源代码,而是创建了第一个文本区域,以便我可以将要清理的代码复制到其中。然后在按下提交按钮时,表单会发布到同一页面,并在第二个文本区域中显示整理好的源代码。显示这个整理好的源代码是问题所在。 通过 HTML tidy 传递以下代码并尝试在文本区域中显示输出,会破坏输出显示。我的意思是,如果你注意到,我有</textarea>
在以下 html 代码中。一旦 Tidy 遇到它,它就会关闭 textarea 并解析源代码的其余信息,就好像它是 HTML 文档的一部分一样,从而破坏了我的整个 html 表单页面(test.php)。
我传递给 HTML TIDY 的示例源代码:
<!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 整洁参数:
$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 tidy 的不同参数,但它没有用。我什至尝试将其输出为 XML,但这并没有帮助。如何让 Tidy 在第二个文本区域中正确显示已清理的源代码,而不会破坏/解析</textarea>
我要清理的源代码的标签?