动网论坛,站长建站首选,国内使用量最多的论坛软件 动网论坛官方技术讨论区 站长工具 申请属于您自己的免费论坛
首页 | 新闻资讯 | 网站运营 | 网络编程 | 数据库 | 服务器 | 网页设计 | 图像媒体 | 网络应用 | 搜索优化 | 资源下载 | 动网主机 | DVBOX
    本站内  互联网 ASP论坛  ASP.Net论坛  PHP论坛
  
   PHP → 阅读文章

 HTML to XHTML Converter

作者来源: 
阅读 数 388 人次 , 2006-3-29 4:08:00 


<?

if (!empty($type)) {
if ($type == "path") {
if (!empty($path)) {
if (file_exists($path) && is_file($path)) {
$file = file($path);
if (substr($file[0],0,9) != "<!doctype") $doctype=0;
$file = join('', $file);
} else {
die ("no such file.");
}
} else {
die ("no file specified.");
}
} elseif ($type == "file") {
if (!empty($file)) {

} else {
die ("no file specified.");
}
} else {
die ("no file specified.");
}

# specify html file, check for doctype
//$file = file("file.html");
//if (substr($file[0],0,9) != "<!doctype") $doctype=1;
//$file = join('', $file);

# make tags and properties lower case, close empty elements, quote all properties
$search = array ("'(<\/?)(\w+)([^>]*>)'e",
 "'(<\/?)(br|input|meta|link|img)([^>]*)( />)'ie",
 "'(<\/?)(br|input|meta|link|img)([^>]*)(/>)'ie",
 "'(<\/?)(br|input|meta|link|img)([^>]*)(>)'ie",
 "'(\w+=)(\w+)'ie",
 "'(\w+=)(.+?)'ie");
$replace = array ("'\\1'.strtolower('\\2').'\\3'",
 "'\\1\\2\\3>'",
 "'\\1\\2\\3>'",
 "'\\1\\2\\3 /\\4'",
 "strtolower('\\1').'\"\\2\"'",
 "strtolower('\\1').'\\2'");
$file = preg_replace($search, $replace, $file);

# return xhtml-compliant document
echo "<textarea cols=\"100\" rows=\"20\">";
if (isset($doctype)) echo '<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "dtd/xhtml1-transitional.dtd">'."\n";
echo stripslashes(stripslashes(stripslashes($file)));
echo "</textarea>";

} else {
?>
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "dtd/xhtml1-transitional.dtd">
<head><title>html -> xhtml convertor</title></head>

<body>

<!-- warning: this input method is a security risk on open servers //-->
<form action="<?=$php_self?>" method="get">
<input type="hidden" name="type" value="path" />
<font face="verdana">file path:</font> <input type="text" name="path" size="50" />
<input type="submit" value="submit" />
</form>

<b><font face="verdana">or</font></b><br /><br />

<form action="<?=$php_self?>" method="get">
<input type="hidden" name="type" value="file" />
<font face="verdana">file contents:</font><br />
<textarea name="file" rows="10" cols="50"></textarea><br />
<input type="submit" value="submit" />
</form>

</body>

</html>
<?
}
?>

 本文TagsHTML/CSS  
 收藏本文  打印本文  论坛讨论  关闭窗口
· 上一篇:一个获取随机颜色生成在 · PHP中 ADOdb 类库介绍
· UNIX下ORACLE数据库的创建
· 用PHP制作静态网站的模板框架
· 做个自己站内搜索引擎
· 中文注释的php.ini


关于本站 | 联系我们 | 业务合作 | 客户案例 | 诚聘英才 | 广告合作 | 收藏本站
海口动网先锋网络科技有限公司版权所有
Copyright © 2000 - 2006 Cndw.Com
中华人民共和国电信与信息服务业务经营许可证编号 琼 ICP 020077