文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>HTML to XHTML Converter

HTML to XHTML Converter

时间:2007-02-17  来源:PHP爱好者

<?

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'",
"'123>'",
"'123>'",
"'123 /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>
<?
}
?>


php爱好者站 http://www.phpfans.net dreamweaver|flash|fireworks|photoshop.
相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载