PHP HTMLTidy类的用法
我如何使用 示例:我想美化包含HTML的PHP HTMLTidy类的用法,php,html,html-parsing,htmltidy,Php,Html,Html Parsing,Htmltidy,我如何使用 示例:我想美化包含HTML的$input变量。我试过这个: $input = "<html><head><title>The Last Page of the Internet</title></head><body><center><h1><b><u>Attention:</u></b></h1><p><br&
$input
变量。我试过这个:
$input = "<html><head><title>The Last Page of the Internet</title></head><body><center><h1><b><u>Attention:</u></b></h1><p><br><strong>You have reached the very last page of the Internet.</strong></p><p><br><strong>We hope you have enjoyed your browsing.</strong></p><p><br><strong>Now turn off your computer and go outside.</strong></p></center></body></html>";
include ('class.htmltidy.php');
$html = htmltidy($input);
echo $html;
$input=“互联网的最后一页注意:
你已经到达了互联网的最后一页。
我们希望你浏览得愉快。
现在关掉你的电脑到外面去。
;
包括('class.htmlidy.php');
$html=HTMLIDY($input);
echo$html;
但这是行不通的
可以找到HTMLTidy类的源。您说要“美化”输入html。没有办法知道这意味着什么。也就是说,我真的不知道HTMLTidy类应该做什么。它有一个方法“parse”。我试过:
$input = "<html><head><title>The Last Page of the Internet</title></head><body><center><h1><b><u>Attention:</u></b></h1><p><br><strong>You have reached the very last page of the Internet.</strong></p><p><br><strong>We hope you have enjoyed your browsing.</strong></p><p><br><strong>Now turn off your computer and go outside.</strong></p></center></body></html>";
$tidy = new htmltidy();
$tidy->parse($input);
print_r($tidy->html);
有关更多信息,请参阅。$input的内容是什么?从您的示例来看,$input似乎是单元化的。@RobApodaca我已经包括$input请参见编辑。下一步,定义“不工作”。@GolezTrol很抱歉输入错误。“美化”是指缩进HTML以获得更好的布局。当我运行你的代码时,我还有一个空数组。我不能使用php tidy扩展,因为没有安装libtidy,我也不能安装它,因为服务器不是我的。所以我在寻找一个PHP类,我找到了HTMLTidy类。也许还有另一个PHP类或解决方案,但我不知道。
$tidy = tidy_parse_string($input, array(
'output-html' => true,
'indent' => true,
));
$tidy->cleanRepair(); //if you might have markup errors
echo $tidy;