The author has 3 posts.
Font size: Small - 100% (Default)  Content converter: No conversion
 
Clicks Replies
1566 2
PHP Tidy庫修復HTML代碼
巨大八爪鱼
武林盟主 二十一级
Reply
Floor 1 Posted at: 6/13/15 20:37
<?php
ob_start(); //開始捕獲HTML代碼(包含標籤錯誤的)
?>
<html>
  <head>
    <title>What</title>
  </head>
  <body>
    <p>error</i>
    <div>
    <ul>
      <li>aaaaaaa
  </body>
</html>
<?php
$buffer = ob_get_clean(); //捕獲結束,以上內容不會被輸出!
$tidy = new tidy();
$clean = $tidy->repairString($buffer); //修復HTML
echo $clean; //重新輸出修復了的HTML
?>
巨大八爪鱼
武林盟主 二十一级
Reply
Floor 2 Posted at: 6/13/15 20:37
修復後的結果:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html>
<head>
<title>What</title>
</head>
<body>
<p>error</p>
<div>
<ul>
<li>aaaaaaa</li>
</ul>
</div>
</body>
</html>
巨大八爪鱼
武林盟主 二十一级
Reply
Floor 3 Posted at: 6/13/15 20:39
http://php.net/manual/en/book.tidy.php
Reply the post
Content:
User: You are currently anonymous.
Captcha:
Unclear? Try another one.
(Shortcut key: Ctrl+Enter)
Post Information
Clicks: 1566 Replies: 2
Author: 巨大八爪鱼
Last reply: 巨大八爪鱼
Last reply time: 6/13/15 20:39
Bar Hot Posts
Announcements