我使用this php code代碼來寫出我的css與填充變量。在一個php文件中設置數組並訪問另一個php文件問題
我想默認的陣列搬出這個代碼,並將其提升到settings.php
文件爲我的網站,但是當我做我收到此錯誤信息:
<b>Warning</b>: extract() [<a href='function.extract'>function.extract</a>]: First argument should be an array in <b>/home/drawapl1/public_html/ezamazon/demo/css/stylesheet.php</b> on line <b>19</b>
我的代碼如下:
在index.php文件:
<?php
include("settings.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link href="css/stylesheet.php" rel="stylesheet" type="text/css" media="screen" />
在stylesheet.php:
/* get the stylesheet */
$stylesheet = @is_file($_GET['stylesheet']) && strtolower(substr(strrchr($file_name,'.'),1)) == 'css' ? $_GET['stylesheet'] : 'global.css';
/* set the header information */
//will be output as css
header('Content-type: text/css');
//set an expiration date
$days_to_cache = 10;
header('Expires: '.gmdate('D, d M Y H:i:s',time() + (60 * 60 * 24 * $days_to_cache)).' GMT');
//red css variable information
//$red = array(
//'body_font_size' => '10px',
//'body_text_color' => '#f00'
//);
/* extract the propery array's information */
extract($_GET['theme'] && ${$_GET['theme']} ? ${$_GET['theme']} : $defaultCSS);
/* load in the stylesheet */
$content = preg_replace('/\$([\w]+)/e','$0',@file_get_contents($stylesheet));
/* spit it out */
echo $content;
在settings.php配置:
$defaultCSS = array( 'body_background_colour' => 'white', 'body_text_colour' => 'black', 'body_font_size' => '1em', 'body_font_family' => 'Arial, Helvetica, sans-serif', 'h1_text_colour' => 'black', 'h2_text_colour' => 'black', 'h3_text_colour' => '#E47911', 'a_text_colour' => '#004B91', 'a_hover_text_colour' => '#2A70FC', 'news_block_background_colour' => '#EAF3FE', 'left_nav_border_colour' => '#C9E1F4', 'left_nav_h2_background_colour' => '#EAF3FE', 'button_text_colour' => '#FFFFFF', 'button_background_colour' => '#414953', 'button_hover_background_colour' => '#999999', 'price_colour' => '#990000', 'price_heading_colour' => '#666666', 'nav_links_colour' => 'black', 'nav_hover_links_colour' => '#E47911', 'hr_divider_colour' => '#DDDDDD', 'pagination_highlight_colour' => '#645538' );
任何想法的問題是什麼?
在此先感謝。
爲什麼你不會使用實際的代碼**? – zerkms 2012-03-14 00:37:47
你的代碼是什麼樣的,'settings.php'會在樣式表php之前加載嗎? – jeroen 2012-03-14 00:39:04
'$ {$ _ GET ['theme']}'不是數組。你能否迴應'$ _GET ['theme']'的價值並在這裏發佈? – augustknight 2012-03-14 00:39:28