我使用 style.php 作为样式文件.. 这是该文件的一部分
.<?php echo $cty2; ?> {
background: url(images/<?php echo $cty2; ?>.jpg) no-repeat;
}
当我去 style.php (浏览器),这会出现
.newyorkny {
background: url(images/newyorkny.jpg) no-repeat;
}
但是页面背景没有出现!
当我改变这个
.<?php echo $cty2; ?> {
background: url(images/<?php echo $cty2; ?>.jpg) no-repeat;
}
对此(没有php)
.newyorkny {
background: url(images/newyorkny.jpg) no-repeat;
}
然后BG出现了
那么,我如何强制 BG 以 php 样式出现?
========已编辑=============
这是 style.php 文件
<?php
header("Content-Type: text/css ");
?>
@font-face {
font-family: "Segoe WPC";
src: url("http://cdn-resources.windowsphone.com/Resources/Fonts/SegoeWPCRegular/Latin1_1252/87c56796-f4c3-4861-9f31-035d303c63ce-1.ttf") format("truetype");
font-style: normal;
font-weight: normal;
}
@font-face {
font-family: "Segoe WPC Light";
src: url("http://cdn-resources.windowsphone.com/Resources/Fonts/SegoeWPCLight/Latin1_1252/bd84c8dc-054a-427a-9fde-3ebb63965f38-1.ttf") format("truetype");
font-style: normal;
font-weight: normal;
}
@font-face {
font-family: "Segoe WPC Black";
src: url("http://cdn-resources.windowsphone.com/Resources/Fonts/SegoeWPCBlack/Latin1_1252/f513a30a-82ae-4466-acac-96337207a433-1.ttf") format("truetype");
font-style: normal;
font-weight: bold;
}
body {
color:#a8a8a8;
font-family: 'Segoe WPC', Segoe UI, Arial, Tahoma, sans-serif;
font-size:13px;
margin:0;
padding:0;
background: #141414;
}
img { margin: 2px; }
h1 {
margin-top: 5px;
font-weight:400;
}
a {
color:#a8a8a8;/*333*/
text-decoration: none;
}
a:hover {
color:#eee;
}
option {
font-weight: bold;
}
option:hover {
cursor: pointer;
}
img { border: 0 }
input, select, textarea {
font-family: 'Segoe WPC', Segoe UI, Arial, Tahoma, sans-serif;
border:1px solid #D9D9D9;
border-top:1px solid #C0C0C0;
font-size:14px;
outline:none;
padding:5px;
}
input:hover, select:hover, textarea:hover{
border:1px solid #C0C0C0;
border-top: 1px solid #777;
}
input:focus, select:focus, textarea:focus {
border:1px solid #2a2a2a;
box-shadow: inset 0 1px 2px rgba(0,0,0,0.3);
}
input#search {
width: 176px;
background: #f0f0f0;
border:2px solid #000;
font-size:14px;
outline:none;
padding:5px;
color:#aaa;
margin-top: 10px;
}
input#search:hover {
background: #fff;
color: #202020;
}
input#search:focus {
background: #fff;
color: #202020;
}
hr {
border:none;
color:white;
height:1px;
background:#ccc;
background: -webkit-gradient(radial, 50% 50%, 0, 50% 50%, 600, from(#ccc), to(#fff));
}
/* Selectie */
::selection {
background:#000;
color:#fff;
}
::-moz-selection {
background:#000;
color:#fff;
}
::-webkit-selection {
background:#000;
color:#fff;
}
/*General*/
#header {
font-family: 'Open Sans', Segoe UI, sans-serif;
margin: 0 auto;
padding: 7px 10px 13px 10px;
height: 69px;
}
#content {
width:1006px;
margin:20px auto 0 auto;
}
.content {
border: 3px solid #000;
width: 1000px;
height: 575px;
background: #fafafa;
}
.Freeze {
background: url(images/bg_freeze.png) no-repeat;
}
.Cold {
background: url(images/bg_cold.png) no-repeat;
}
/* new york */
<?php
function PageMain() {
global $TMPL;
$resultSettings = mysql_fetch_row(mysql_query(getSettings($querySettings)));
$year = date("Y");
$month = date("m");
# Detecteaza locatia IP-ului vizitatorului
include("includes/geoipcity.inc");
include("includes/geoipregionvars.php");
$ip = $_SERVER['REMOTE_ADDR'];
$gi = geoip_open("includes/GeoLiteCity.dat", GEOIP_STANDARD);
$record = geoip_record_by_addr($gi, $ip);
geoip_close($gi);
$city = $record->city;
# Hotaraste ce oras este folosit
if(isset($_GET['city'])) { # Daca e setat ?city schimba
$city = htmlspecialchars($_GET['city']);
} elseif (empty($city)) { # Daca nu deteacteaza locatia IP-ului, pune default
$city = $resultSettings[1];
}
# Preia informatia (cURL pentru formatul UTF-8)
$city = urlencode($city);
$city = utf8_encode($city);
$url = 'http://www.google.com/ig/api?weather='.$city.'&hl=en';
$ch = curl_init();
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt ($ch, CURLOPT_TIMEOUT, 60);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 0);
$utf8 = curl_exec($ch);
curl_close($ch);
$xml = simplexml_load_string($utf8);
# Seteaza preferinta formatului temperaturii
if($_GET['f'] == 'f') {
setcookie("format", 'fahrenhite', time() + 10080);
$TMPL['cf'] = 'f';
$TMPL['f'] = 'c';
} elseif($_GET['f'] == 'c') {
setcookie("format", 'celsius', time() + 10080);
$TMPL['cf'] = 'c';
$TMPL['f'] = 'f';
} elseif($_COOKIE['format'] == '') {
$TMPL['cf'] = 'c';
$TMPL['f'] = 'f';
} elseif($_COOKIE['format'] == 'fahrenhite') {
$TMPL['cf'] = 'f';
$TMPL['f'] = 'c';
} elseif($_COOKIE['format'] == 'celsius') {
$TMPL['cf'] = 'c';
$TMPL['f'] = 'f';
}
# Defineste radacinile in variabile cu xpath
$information = $xml->xpath("/xml_api_reply/weather/forecast_information");
$current = $xml->xpath("/xml_api_reply/weather/current_conditions");
$forecast = $xml->xpath("/xml_api_reply/weather/forecast_conditions");
$cty = $information[0]->city['data'];
$ctyy = utf8_encode($cty);
if(isset($_COOKIE['username']) && isset($_COOKIE['password'])) {
$query = sprintf('SELECT * from users where username = "%s" and password ="%s"',
mysql_real_escape_string($_COOKIE['username']),
mysql_real_escape_string($_COOKIE['password']));
if(mysql_fetch_row(mysql_query($query))) {
$user = $_COOKIE['username'];
if($_GET['fav'] == '1') {
$query = sprintf("INSERT INTO favorites (`username`, `location`) values ('%s', '%s')",
mysql_real_escape_string($user),
mysql_real_escape_string($city));
mysql_query($query);
}
if(isset($_GET['city'])) {
$TMPL['fav'] = '?city='.$_GET['city'].'&fav=1';
} else {
$TMPL['fav'] = '?fav=1';
}
} else {
$user = 'anonymous';
$TMPL['notLogged'] = '<despartitor></despartitor>You must be logged in to add favorites';
}
} else {
$user = 'anonymous';
$TMPL['notLogged'] = '<despartitor></despartitor>You must be logged in to add a city to favorites.';
}
$cookieFormat = $TMPL['cf']; # Seteaza variabila cookies format, ca s-o pot folosi si in rows
$TMPL_old = $TMPL; $TMPL = array();
$skin = new skin('welcome/rows'); $all = '';
# Citeste formatul ales de user, si arata-i informatiile in formatul ales de el
if($cookieFormat == 'f') {
foreach($forecast as $foreca) {
$TMPL['day'] = $foreca->day_of_week['data'];
$TMPL['low'] = $foreca->low['data'].'°';
$TMPL['high'] = $foreca->high['data'].'°';
$TMPL['icon'] = str_replace(array('/ig', '.gif'), array('', '.png'), $foreca->icon['data']);
$TMPL['condition'] = $foreca->condition['data'];
$all .= $skin->make();
}
} else {
foreach($forecast as $foreca) {
$TMPL['day'] = $foreca->day_of_week['data'];
$TMPL['low'] = round(($foreca->low['data'] - 32) /1.8, 0).'°'; # Converteste din Fahrenhite in Celsius
$TMPL['high'] = round(($foreca->high['data'] - 32) /1.8, 0).'°'; # Converteste din Fahrenhite in Celsius
$TMPL['icon'] = str_replace(array('/ig', '.gif'), array('', '.png'), $foreca->icon['data']);
$TMPL['condition'] = $foreca->condition['data'];
$all .= $skin->make();
}
}
$TMPL = $TMPL_old; unset($TMPL_old);
$TMPL['rows'] = $all;
if($cookieFormat == 'f') {
$TMPL['city'] = $information[0]->city['data'];
$TMPL['temp'] = $current[0]->temp_f['data'].'°';
$cty = trim($TMPL['city']);
$cty2 = str_replace(" ", "", "$cty");
$cty2 = str_replace(",", "", "$cty2");
$cty2 = strtolower($cty2);
$ct = $TMPL['city'];
$TMPL['weather'] = $cty2;
mysql_query("INSERT INTO city (city, css, year, month) VALUES ('$city','$cty2','$year','$month')");
$year = date("Y");
$month = date("m");
} else {
$TMPL['city'] = $information[0]->city['data'];
$TMPL['temp'] = $current[0]->temp_c['data'].'°';
$cty = trim($TMPL['city']);
$cty2 = str_replace(" ", "", "$cty");
$cty2 = str_replace(",", "", "$cty2");
$cty2 = strtolower($cty2);
$ct = $TMPL['city'];
$TMPL['weather'] = $cty2;
$ce = $TMPL['city'];
$query2 = "SELECT * FROM city WHERE city='$ce' ";
$result2 = mysql_query($query2) or die(mysql_error());
while($row2 = mysql_fetch_array($result2)) {
$visits = $row2['visits'];
}
if (mysql_num_rows($result2)){
mysql_query("UPDATE city SET visits='$visits'+1 WHERE city='$ce' ");
}
else
{
$visits = '1';
$query3 = "INSERT INTO city (city, css, visits) VALUES ('$ce','$cty2','$visits')";
$result3 = mysql_query($query3) or die(mysql_error());
}
$cty2 = utf8_encode($cty2);
$con = mysql_connect("localhost","hatim_wea","*F7W,vrBEzC=");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
$sel = mysql_select_db("hatim_weather", $con) or die();
$ce = $TMPL['city'];
$queryw = "SELECT * FROM city where city='$ce' ";
$resultw = mysql_query($queryw,$con) or trigger_error("SQL", E_USER_ERROR);
$numw = "mysql_num_rows($queryw)";
while($roww = mysql_fetch_array($resultw)) {
$sete = $roww["city"];
$visits = $roww["visits"];
$cess = $roww["css"];
}
if (mysql_num_rows($resultw)){
$ss = utf8_encode($cess);
echo"
.$ss {
background: url(images/$ss.jpg);
}
";
}
}
}
require_once('./includes/config.php');
require_once('./includes/skins.php');
require_once('./includes/functions.php');
mysql_connect($conf['host'], $conf['user'], $conf['pass']);
mysql_query('SET NAMES utf8');
mysql_select_db($conf['name']);
$TMPL['content'] = PageMain();
?>