html_include() 使用方法
<?php
include_once "html_head.php";
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<!--该函数不限制参数个数,自动根据后缀echo对应的引入文件-->
<!--注意写了网页标题会自动引入meta和logo,标题不能以.js或.css或.php结尾-->
<?php html_include("网页标题","bootstrap.min.css");?>
</head>
<body>
<?php html_inlcude("jquery.min.js");?>
</body>
</html>
html_head.php 源码
<?php
//js和css的版本号
$g_html_version = 20190413;
//js和css对应的路径数组
$g_html_link_ary = array(
"bootstrap.min.css" => array("/public/css/bootstrap/bootstrap.min.css"), //说明
"jquery.min.js" => array("/public/js/jquery/jquery.min.js"),//说明
);
function html_include(){
global $g_html_link_ary;
global $g_html_version;
$css_link = '<link rel="stylesheet" type="text/css" href="';
$js_link = '<script type="text/javascript" src="';
//所有的html标签头
$head = '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
$head .= '<meta http-equiv="X-UA-Compatible" content="IE=edge">';
$head .= '<meta http-equiv="Pragma" CONTENT="no-cache">';
$head .= '<meta http-equiv="Cache-Control" CONTENT="no-cache">';
$head .= '<link rel="icon" id="url_logo" href="//www.greatytc.com/public/img/url_logo.ico?v='.time().'" type="image/x-icon" />';
//获取入参
$num=func_num_args();
$list=func_get_args();
$renum=0;
// 遍历入参
for($i=0;$i<$num;$i++)
{
$t_type = substr($list[$i], strrpos($list[$i],".")+1);
if( $t_type == "css" )
{
//输出网页的css文件
echo $css_link.$g_html_link_ary[$list[$i]][0]."?v=".$g_html_version."\"/>";
}
else if( $t_type == "js" )
{
//输出网页的js文件
echo $js_link.$g_html_link_ary[$list[$i]][0]."?v=".$g_html_version."\"/></script>";
}
else if( $t_type == "php" )
{
//预留echo 语言包
}
else
{
echo $head;
//网页的标题
echo "<title>".$list[$i]."</title>";
}
}
}
?>