php页面meta头设置

public static function getPageMeta($paramArr) {
        if (is_array($paramArr)) {
            $options = array(
                'id'          => 0,       #详情id
                'indexFlag'   => 0,       #首页标示
                'noFollow'    => 0,       #是否允许搜索引擎抓取
                'noCache'     => 0,       #是否缓存
                'chartSet'    => 'GBK',   #默认字符集
                'pageType'    => '',      #页面类型,暂时没用到
                'title'       => '',      #页面标题
                'keywords'    => '',      #页面关键字
                'description' => '',      #页面表述
            );
            $options = array_merge($options, $paramArr);
            extract($options);
        }
        
        #页面编码
        $metaStr = '<meta charset="' . $chartSet . '" />' . "
	";
        if($indexFlag == true){ #首页
            $metaStr.= '<meta http-equiv="mobile-agent" content="format=html5; url=http://m.zol.com.cn/z/" />' . "
	";
        }else if($pageType == 'Detail' ){#详情页
            $metaStr.= '<meta http-equiv="mobile-agent" content="format=html5; url=http://m.zol.com.cn/article/'.$id.'.html" />' . "
	";
        }
        
        if (!empty($noFollow)) {  #如果不允许搜索引擎抓取
            $metaStr .= '<meta name="ROBOTS" content="NOINDEX, NOFOLLOW" />' . "
	";
        }

        if (!empty($noCache)) {   #如果不允许缓存
            $metaStr .= '<meta http-equiv="pragma" content="no-cache" />' . "
	";
        }
 
        if (!empty($title)) {     #如果有标题
            $metaStr .= '<title>' . $title . '</title>' . "
	";
        }

        if (!empty($keywords)) {  #如果有关键字
            $metaStr .= '<meta name="keywords" content="' . $keywords .'" />' . "
	";
        }

        if ($description) {       #如果有描述
            $metaStr .= '<meta name="description" content="' . $description .'" />' . "
";
        }
        #所有pc端页面禁止转码并且声明设备
        $metaStr .= '<meta http-equiv="Cache-Control" content="no-siteapp"/>'."
	";
        $metaStr .= '<meta http-equiv="Cache-Control" content="no-transform"/>'."
	";
        $metaStr .= '<meta name="applicable-device" content="pc">'."
	";
        return $metaStr;
    }
原文地址:https://www.cnblogs.com/doubilaile/p/9176511.html