我们程序员和页面美工是经常配合的,当我们碰到一个有经验的,制作页面代码整洁的页面制作人员呢,那真是我们程序员的福气,写代码的效率都提高了,如果碰到一个刚入行的,那就痛苦了,光看他们做的页面代码就头大了,大部分时间要花在给他们做的代码找错上面。现在随着HTMLArea、 FCKeditor 等免费又功能强大的 WYSWYG在线编辑器的流行,我们就更加需要修正由用户造成的HTML代码错误。
  不过现在好了,我们可以直接用php函数来修复页面代码,HTML Tidy Library包已经被整合到了PHP5,所以我们在PHP5下面就可以直接使用tidy函数了。
tidy函数库有下面这些函数:
引用
ob_ tidyhandler
tidy_ access_ count
tidy_ clean_ repair
tidy_ config_ count
tidy:: _ _ construct
tidy_ diagnose
tidy_ error_ count
tidy_ get_ body
tidy_ get_ config
tidy_ get_ error_ buffer
tidy_ get_ head
tidy_ get_ html_ ver
tidy_ get_ html
tidy_ get_ opt_ doc
tidy_ get_ output
tidy_ get_ release
tidy_ get_ root
tidy_ get_ status
tidy_ getopt
tidy_ is_ xhtml
tidy_ is_ xml
tidy_ load_ config
tidy_ node-> get_ attr
tidy_ node-> get_ nodes
tidy_ node-> next
tidy_ node-> prev
tidy_ parse_ file
tidy_ parse_ string
tidy_ repair_ file
tidy_ repair_ string
tidy_ reset_ config
tidy_ save_ config
tidy_ set_ encoding
tidy_ setopt
tidy_ warning_ count
tidyNode-> hasChildren
tidyNode-> hasSiblings
tidyNode-> isAsp
tidyNode-> isComment
tidyNode-> isHtml
tidyNode-> isJste
tidyNode-> isPhp
tidyNode-> isText


我们只看几个最常用函数,其他的自己研究哦,下面看看tidy_repair_string例子:
程序代码:

<?php
ob_start();
?>

<html>
 <head>
  <title>test</title>
 </head>
 <body>
  <p>error</i>
 </body>
</html>

<?php

$buffer = ob_get_clean();
$tidy = tidy_repair_string($buffer);

echo $tidy;
?>

输出结果:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html>
<head>
<title>test</title>
</head>
<body>
<p>error</p>
</body>
</html>

看看错误被修正了,呵呵,所以我们对于用户通过在线编辑器输入的内容都应该用tidy修复。
Tags: , ,
PHP | 评论(0) | 引用(0) | 阅读(14985)
发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   游客无需密码
网址   电邮   [注册]