如何使用php存储和调用多个样式表?

时间:2015-11-15 21:33:23

标签: php

我试图在.php文件中存储多个样式表,我想通过url调用这些文件:

<link rel='stylesheet' href='style.php?stylesheet1'>

和另一个应该采用不同样式的页面:

<link rel='stylesheet' href='style.php?stylesheet2'>

我目前正在使用数组编译多个样式表,然后使用我发现的缩小它们的脚本

$cssFiles = array(
"templates/css/part1.css",
"templates/css/part2.css"
);

1 个答案:

答案 0 :(得分:-1)

你可以尝试这样的事情

<强>的index.html

<link rel='stylesheet' href='style.php?style=1'>
<link rel='stylesheet' href='style.php?style=2'>

<强> style.php

<?php
$cssFiles = array(
"/templates/css/part1.css",
"/templates/css/part2.css"
);


$file = (isset( $_GET['style'] ) && is_numeric($_GET['style'])) ? intval($_GET['style'] ) : '';

if(!empty($file) && isset($cssFiles[$file - 1]))
    $file = $cssFiles[$file - 1];
    else
    $file = $cssFiles[0];

if(file_exists($file))
    include $file;

    ?>