嗨,我想做以下事情:
$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?