【问题标题】:How to send a well formed HTML document to the client?如何向客户端发送格式良好的 HTML 文档?
【发布时间】:2013-02-18 15:54:22
【问题描述】:

您好,我想做以下事情:

$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 编译器呢? :o
  • 不是测验!是个问题...有这个功能或库吗?
  • CrisHongKongCRISHK:@SiGateng 的意思是,你为什么不自己尝试一下你的例子呢?这会告诉你会发生什么。我们希望您在现场询问之前这样做,因此实际上(更)清楚您的具体编程问题是什么。到目前为止,您得到的答案的质量可能与您想象的一样低。

标签: php html xml dom domdocument


【解决方案1】:

有一个名为 PHP Simple HTML Dom Parser 的库。它很好用,绝对可以帮助您验证 HTML。

PHP Simple HTML DOM Parser

【讨论】:

    【解决方案2】:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-07-13
      • 2012-10-27
      • 2014-03-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-10
      相关资源
      最近更新 更多