2013-02-18 75 views
0

您好我想做到以下几点:如何将格式正确的HTML文档发送给客户端?

$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!"; 

¿如何$秀= ......................... {$ string_foo} ......将会返回一个格式良好的HTML吗?

+5

这是一个测验?为什么不尝试使用你的PHP编译器? :o – 2013-02-18 07:11:09

+0

不是测验!是一个问题...有这样的功能或库? – 2013-02-18 07:20:32

+0

CrisHongKongCRISHK:@SiGateng的意思是,你为什么不尝试自己的例子?,这会告诉你发生了什么。我们希望在网站上提出这个问题,然后再询问是否确实(更清楚)你的具体编程问题是什么。到目前为止,你得到的答案质量都很低,正如你可能想象的那样。 – hakre 2013-02-18 08:18:22

回答

0

有一个库叫做PHP Simple HTML Dom Parser。它工作的很好,它绝对可以帮助您验证HTML。

PHP Simple HTML DOM Parser

+0

该库不好! – 2013-02-18 07:17:23

+0

当我需要它进行一些刮擦时,它对我很好。 – 2013-02-18 07:18:19

相关问题