Css in Php Datei einbinden

Zinodan

Grünschnabel
Grüße,
ich zerbreche mir gerade den Kopf wie ich es erreichen kann eine Css Datei in einem php Skript einzubinden.

Dazu muss ich sagen das ich ein ziemlicher anfänger bin.

Danke im Antwort
 
Hä? Was is daran schwierig?

PHP:
Bla bla

<div style="background-color:#12345; border: 1px solid #010245;">
<?php echo $variable ?>
</div>
 
Zuletzt bearbeitet von einem Moderator:
Das ist egal ob du deine Definitionen im Tag mit style machst oder einfach eine CSS Datei einbaust. Hast du dir schonmal den Quellcode einer php Seite angesehen, wenn diese aufgerufen wurde? Da steht nichts mehr von <?php .... ?> sondern nur noch ganz normale HTML Tags, darum musst du auch nichts beachten wenn du ein CSS file einbindest, das funktioniert ganz normal wie bei einer html Seite.
 
Hmm, die Datei die ich bearbeitet möchte ist aber nur in php geschrieben. Schaut selber:

<?php
$psuroot = str_replace("\\","/",dirname(__FILE__));
$scriptpath = $psuroot;
$psuroot = substr($psuroot,0,strrpos($psuroot, "/"));
$phpext = strrchr (__FILE__, ".");

include($psuroot."/lib/ini.class".$phpext);
include($psuroot."/lib/template.class".$phpext);
include($psuroot."/lib/textdb.class".$phpext);
include($psuroot."/lib/lib".$phpext);

$ini = new Ini($scriptpath."/cfg".$phpext);
$table = new TextDB($scriptpath."/data/data");

$count = $ini->Get("count");
$pos = ($_POS == "") ? 0 : $_POS;

$actpos = 0;
$newscount = 0;
if ($table->DoOpen()) {
if ($table->DoSelect("ORDER date_start DESC",$pos,$count)) {
do {
$id = $table->QueryGet("id");
$date_start = TimestamptoDate($table->QueryGet("date_start"));
$topic = $table->QueryGet("topic");
$shortinfo = ReadContentFromFile($table->QueryGet("shortinfo"),$scriptpath."/data/");
$shortpic = $table->QueryGet("shortpic");
$longinfo = $table->QueryGet("longinfo");

$tpl = new Template($scriptpath."/article.tpl");
$tpl->Replace(":date",$date_start);
$tpl->Replace(":topic",$topic);
$tpl->Replace(":shortinfo",$shortinfo);
if ($shortpic == "") $tpl->Remove(":php1"); else
$tpl->Replace(":shortpic","data/{$shortpic}");
if ($longinfo == "") $tpl->Remove(":php2"); else
$tpl->Replace(":showarticle","show{$phpext}?_ID=$id");
$tpl->CleanUp();
$news .= $tpl->Content();
$newscount++;
} while ($table->QueryNext() && ($newscount < $count));
}
}

$tpl = new Template($scriptpath."/page.tpl");
$tpl->Replace("spacer1",$news);
if ($table->QueryPrevAvailable()) $tpl->Replace(":navigate-prev","index{$phpext}?_POS=".($pos-$count < 0 ? 0 : $pos-$count));
else $tpl->Remove(":php1");
if ($table->QueryNextAvailable()) $tpl->Replace(":navigate-next","index{$phpext}?_POS=".($pos+$count));
else $tpl->Remove(":php2");
$tpl->CleanUp();
$tpl->Output();
?>
 
Also vielleicht hab ich mich undeutlich ausgedrückt. In deiner Datei hast du ein einziges Tag, nämlich <?php ... ?>
Es spricht meines Erachtens nichts dagegen, wenn du davor ein
<link rel="stylesheet" type="text/css" href="yourfile.css">
setzt.
Da du allerdings mit Templates arbeitest (es handelt sich wohl um ein Newsskript), ist das bestimmt eine html Datei die das verwendet. Ich würde dort das css file einbinden.
Wenn dich das alles nicht zufrieden stellt, dann mach das mal so:
Am Anfang des php Teils sagst du
PHP:
$cssfile = "<link rel=\"stylesheet\" type=\"text/css\" href=\"yourfile.css\">
";
echo $cssfile;
( P.S.: Da du allerdings selbst sagst, dass du ziemlicher Anfänger in php bist, glaube ich nicht, dass da auch nur eine Zeile von dir geschrieben wurde. Such mal bei galileo computing das php4 buch, falls ich mich geirrt hab, benutzt du phplib?)
 
Oder willst du in die CSS-Datei, die du einbindest, PHP verarbeiten?
PHP:
#bla.html
...
<link rel="stylesheet" href="css.php?bgcolor=123456" type="text/css">


#css.php:

<?php
header("Content-type: text/css");
?>
body {
  background-color: #<?php echo $_GET["bgcolor"] ?>;
}
 
Fluessig:
Es spricht meines Erachtens nichts dagegen, wenn du davor ein <link rel="stylesheet" type="text/css" href="yourfile.css">
setzt.

Man bin ich blöd ;) Ich hatte die Zeile im <Head> eingebunden...
Deswegen ging es nicht !

Danke dir
 
Zurück