您现在的位置: 365建站网 > 365文章 > HTML to XHTML Converter

HTML to XHTML Converter

文章来源:365jz.com     点击数:264    更新时间:2008-07-26 19:56   参与评论

<?

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>
<?
}
?>

如对本文有疑问,请提交到交流论坛,广大热心网友会为你解答!! 点击进入论坛

发表评论 (264人查看0条评论)
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
昵称:
最新评论
------分隔线----------------------------

快速入口

· 365软件
· 杰创官网
· 建站工具
· 网站大全

其它栏目

· 建站教程
· 365学习

业务咨询

· 技术支持
· 服务时间:9:00-18:00
365建站网二维码

Powered by 365建站网 RSS地图 HTML地图

copyright © 2013-2024 版权所有 鄂ICP备17013400号