Closed Thread Icon

Topic awaiting preservation: CSS In PHP (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=12863" title="Pages that link to Topic awaiting preservation: CSS In PHP (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: CSS In PHP <span class="small">(Page 1 of 1)</span>\

 
KARN
Bipolar (III) Inmate

From: North Bay, Ontario, CA
Insane since: Apr 2001

posted posted 08-18-2003 07:08

how do i link to a css doc in a php script using echo("... tags...?

kuckus
Bipolar (III) Inmate

From: Berlin (almost)
Insane since: Dec 2001

posted posted 08-18-2003 07:21
code:
echo '<link rel="stylesheet" href="/path/to/styles.css" title="Default Site Styles" type="text/css" />';

should do it.

Skaarjj
Maniac (V) Mad Scientist

From: :morF
Insane since: May 2000

posted posted 08-18-2003 07:26

yeah...that should definatley do it. With PHP you have ot remember that if you have ot do anything that involves normal HTML code, stick it in an echo with single quotes around it, plug whatever you want in there and it will work...just make sure with things like links to style sheets that you put them right up the top of the page, since they're part of the header information.

Veneficuz
Paranoid (IV) Inmate

From: A graveyard of dreams
Insane since: Mar 2001

posted posted 08-18-2003 10:55

You can also stick the html code into a print or echo statement with double quotes, you just have to remember to escape all the double quotes used in the html. So you could do:

code:
echo "<link rel=\"stylesheet\" href=\"/path/to/styles.css\" title=\"Default Site Styles\" type=\"text/css\" />";



_________________________
"There are 10 kinds of people; those who know binary, those who don't and those who start counting at zero"

DL-44
Maniac (V) Inmate

From: under the bed
Insane since: Feb 2000

posted posted 08-18-2003 14:32

Just a little clarification -

quote:
put them right up the top of the page, since they're part of the header information.



Whether it's at the top, middle, or bottom is irrelelvant. What matters is that you put it within the <head> tags of the HTML document. =)


KARN
Bipolar (III) Inmate

From: North Bay, Ontario, CA
Insane since: Apr 2001

posted posted 08-18-2003 16:09

Thanks I was actually doing:

echo("<link rel=\"stylesheet\" href=\"/Site/CSS/Nicks.css\" title=\"Default Site Styles\" type=\"text/css\" />\n";

And had a little problem

Skaarjj
Maniac (V) Mad Scientist

From: :morF
Insane since: May 2000

posted posted 08-18-2003 16:35

*smacks head* That's right! Thanks DL

kuckus
Bipolar (III) Inmate

From: Berlin (almost)
Insane since: Dec 2001

posted posted 08-18-2003 17:59

KARN - Your version is almost OK as well, you just forgot the closing bracket at the end.

echo("<link rel=\"stylesheet\" href=\"/Site/CSS/Nicks.css\" title=\"Default Site Styles\" type=\"text/css\" />\n");

trib
Paranoid (IV) Inmate

From: Den Haag, Netherlands
Insane since: Sep 2002

posted posted 08-19-2003 12:17

Personally, call me sloppy if you like, but I can't see the point in doing that if you aren't setting your css filename with a variable within the statement. It would be much more readable to just turn off the php script, put the style tag into the text, and then turn on PHP again ...

code:
?>
<link rel="stylesheet" href="/path/to/styles.css" title="Default Site Styles" type="text/css" />
<?php

unless you intend to implement some sort of skin switcher ...

code:
//some more code to determine the value of index and populate $arrayOfFilenames[]
// followed by something like
$cssFile=$arrayOfFilenames[index];
echo("<link rel=\"stylesheet\" href=\"/Site/CSS/$cssFile\" title=\"Default Site Styles\" type=\"text/css\" />\n";


or something along those lines ...



Bug-free software only exisits in two places
A programmer's mind and a salesman's lips

[This message has been edited by trib (edited 08-19-2003).]

DL-44
Maniac (V) Inmate

From: under the bed
Insane since: Feb 2000

posted posted 08-19-2003 15:08

Good point trib.

Nathus
Nervous Wreck (II) Inmate

From: Minnesota
Insane since: Aug 2003

posted posted 08-25-2003 03:36

Or you could do

quote:
?><link rel="stylesheet" href="/Site/CSS/<?php echo $cssFile $?>" title="Default Site Styles" type="text/css" /><?php



I personally try to avoid echoing html tags. That way, if down the road someone using something like dreamweaver, or frontpage will have an easier time changing little things in the page.

mobrul
Bipolar (III) Inmate

From:
Insane since: Aug 2000

posted posted 08-25-2003 15:08

this addresses Trib's point about easily readable php writing html (or anything else).
If I have to write long blocks of html (or anything else), one of the PHP features I use a lot is like this:

code:
print <<< HTML
<head>
<title>This is the title</title>
<style type='text/css'>
@import "style.css";
</style>
<script type='text/javascript>
...javascript...
</script>
</head>
HTML;



Php will print everything between <<< HTML and HTML; exactly as it is, whitespace and all. HTML can be whatever you want it to be (DOGS, or GIeeUdFdJsHsS, or FRED. Remember, though, it is case sensitive.)
You can also assign variables that way -- just replace 'print' with '$x =';
Maybe you all already know that. I just learned about this recently and I find it useful, a lot.


« BackwardsOnwards »

Show Forum Drop Down Menu