如何将格式良好的HTML文档发送到客户端


How to send a well formed HTML document to the client?

嗨,我想做以下事情:

$string_foo = "Hello world!";
if (is_not_fully_html( $string_foo )) {
   $show = "<!doctype><html><head></head><body>{$string_foo}</body></html>";
}
$dom = new DOMDocument();
$dom->loadHTML( $show );
echo $dom->saveHTML();

但是,如果$string_foo是:会发生什么

$string_foo = "<html>Hello world!</html>";

$string_foo = "<body>Hello world!</body>";

$string_foo = "<head></head><body>Hello world!</body>";

$string_foo = "<head></head>Hello world!";

$string_foo = "<body>Hello world!";

?如何$show=。。。。。。。。。。。。。。。。。。。。。。。。。{$string_foo}。。。。。。会返回格式良好的HTML吗

有一个名为PHP Simple HTML Dom Parser的库它非常有效,而且它绝对可以帮助您验证HTML。

PHP简单HTML DOM解析器

试试这个

KvzHTML库

教程

使用PHP 生成HTML