PHP Tidy:断开文本区域

PHP Tidy:断开文本区域,php,htmltidy,Php,Htmltidy,我有一个html表单页面(test.php),有两个文本区域和一个提交按钮。我创建了第一个textarea,这样我就可以将要清理的代码复制到其中,而不是每次都复制要格式化和硬编码的源代码。然后按下submit按钮,表单将发布到同一页面,并在第二个文本区域显示整理后的源代码显示此整理过的源代码是个问题。通过HTML tidy传递以下代码并尝试在文本区域中显示输出,会中断输出显示。我的意思是,如果您注意到,我在下面的html代码中有。一旦Tidy遇到它,它就会关闭textarea并解析源代码的其余信

我有一个html表单页面(test.php),有两个文本区域和一个提交按钮。我创建了第一个textarea,这样我就可以将要清理的代码复制到其中,而不是每次都复制要格式化和硬编码的源代码。然后按下submit按钮,表单将发布到同一页面,并在第二个文本区域显示整理后的源代码显示此整理过的源代码是个问题。通过HTML tidy传递以下代码并尝试在文本区域中显示输出,会中断输出显示。我的意思是,如果您注意到,我在下面的html代码中有
。一旦Tidy遇到它,它就会关闭textarea并解析源代码的其余信息,就像它是HTML文档的一部分一样,从而破坏我的整个HTML表单页面(test.php)

我正在传递给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>
$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在第二个文本区域正确显示已清理的源代码,而不破坏/解析我试图清理的源代码的
标记?

诀窍是让浏览器根本不将输出的文本视为标记(因为您知道它确实想要),而是,您可以将
替换为
。 浏览器将运行,并将
呈现为

<!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>
</head>    
<?PHP
$text = "</textarea>What's up?"; //Setting a potentially problematic string.

$text = str_replace("<", "&lt;", $text); //Do a find and replace for the < and save it back to the final variable to be rendered later
$text = str_replace(">", "&gt;", $text); //Do a find and replace for the > and save it back to the final variable to be rendered later.
?>
<body>
<div id="wrapper">
<textarea name="css" id="css" cols="150" rows="18">
<?php echo (isset($text) ? $text : ''); ?>
</textarea>

</div><!-- #wrapper -->
</body>
</html>