#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2001
    Location
    Chicago, IL
    Posts
    85
    Rep Power
    13

    linking a .css file to a php script


    Hello everyone.

    I want to link a .css file to my php script. I tried ti include the .cc file but it gave me an error about include_path. I made sure the pathname was correct and it didn't work. Does anyone have any ideas?
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2001
    Location
    New Orleans (in summer); Austin (during school year)
    Posts
    20
    Rep Power
    0
    you don't include it with the include() function. you include it just as you would in HTML (between the HEAD tags):
    Code:
    <link rel="stylesheet" type="text/css" href="styles.css" />
    (or whatever the name of your file is)
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2001
    Posts
    1
    Rep Power
    0
    You can also place the <link> element in another file and include that file.
    For example, you can write a "header.inc" file like this:
    <html>
    <head>
    <title>My Stuff</title>
    <link rel="stylesheet" href="style.css" type="text/css">
    </head>

    and then include the header.inc file in your php file like this
    <?php
    include("header.inc");
    include("otherfiles.inc");
    ?>
  6. #4
  7. No Profile Picture
    Shrill Digital God
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2001
    Location
    Raleigh, NC
    Posts
    64
    Rep Power
    13
    Stylesheets can grow with your site and become pretty complex as different formatting requirements come up. I think it's a good idea to use them with include -- just make sure your include_path is adjusted in php.ini.

    Windows:

    include_path=".;c:\Webshare\Wwwroot\php\"

    Point it to the directory where you want to keep your .inc files and the stylesheet will work.
    I'm not impatient, I just have a low tolerance for boredom.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jul 2001
    Location
    In a constant state of turmoil
    Posts
    858
    Rep Power
    82
    mbritton72 has the answer to the question your asking.

    If you run a phpinfo.php page, you will be able to find out what is set as the current include_path for your php setup. All you have to do then, is put your .css include file in that folder and it should work fine.
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2008
    Posts
    5
    Rep Power
    0
    Originally Posted by andrew dupont
    you don't include it with the include() function. you include it just as you would in HTML (between the HEAD tags):
    Code:
    <link rel="stylesheet" type="text/css" href="styles.css" />
    (or whatever the name of your file is)
    I'm having the same problem, and I tried this solution, but it's not working, though I may have done something wrong. I agree that an include wouldn't help, since that's merely an information organization tool - there's nothing magical about it or anything.

    Question: Should the <link rel="stylesheet" type="text/css" href="styles.css" /> go between the php tags, or inside the header tags?
  12. #7
  13. No Profile Picture
    Sencha Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2001
    Location
    STL
    Posts
    547
    Rep Power
    0
    Originally Posted by n00bEEk
    I'm having the same problem, and I tried this solution, but it's not working, though I may have done something wrong. I agree that an include wouldn't help, since that's merely an information organization tool - there's nothing magical about it or anything.

    Question: Should the <link rel="stylesheet" type="text/css" href="styles.css" /> go between the php tags, or inside the header tags?
    The "correct" way to do it is inside the header tag but it'll work anywhere. I wouldn't mess with the include_path and all that jazz.
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2008
    Posts
    5
    Rep Power
    0
    So, after a genius friend of mine helped me out with this tonight, I tested out the solution, and it works very groovy

    Keep the PHP code and the other DIV or HTML code completely separate:

    Code:
    <head>
    <title>Document Title</title>
    <link href='YourCSSFile.css' rel='stylesheet' type='text/css' />
    </head>
    <body>
    
    <?php
    
    echo "Here are the PHP tags you can put some PHP code into.";
    
    ?> 
    
    <div class='box1'>Some text</div>
    
    </body>
    </html>
    You can also put the PHP Code inside the DIV or HTML code:

    Code:
    <head>
    <title>Document Title</title>
    <link href='YourCSSFile.css' rel='stylesheet' type='text/css' />
    </head>
    <body>
    
    <div class='box1'>
    
    <?php
    
    echo "Here are the PHP tags you can put some PHP code into.";
    
    ?> 
    
    </div>
    
    </body>
    </html>
    It's just that this one doesn't work so well, where you put the DIV or HTML code inside the PHP Code:

    Code:
    <head>
    <title>Document Title</title>
    <link href='YourCSSFile.css' rel='stylesheet' type='text/css' />
    </head>
    <body>
    
    <?php
    
    echo "Here are the PHP tags you can put some PHP code into.
    
    <div class='box1'></div>";
    
    ?> 
    
    </body>
    </html>
    Basically, there are two problems. The main problem is that if you wrap your class='box1' anywhere at all inside the PHP echo, (possibly other PHP, though I'm not advanced enough to know if that's true or not), you'll not have the <link href='YourCSSFile.css' rel='stylesheet' type='text/css' /> actually applying the YourCSSFile.css information to the class='box1' at all. It'll still try to access the YourCSSFile.css file! But the <?PHP echo ''; ?> stuff will hide the class='box1' away from it so it can't apply any of the CSS info to it. You also won't have much luck by doing an inlude of the YourCSSFile.css after the <?PHP portion of anything - unless you're trying to get it to merely print out the YourCSSFile.css info itself onto the web page.

    Also, the other problem with that 3rd scenario has to do with the " vs. the ' issue. Normally, when you write (or use software such as DreamWeaver or FrontPage) HTML/XHTML/etc, you would write something like <a href="http://www.xyz.com/">XYZ.com</a> The " in that code will effectively stop the rest of the PHP tag from executing and cause errors. <a href=//"http://www.xyz.com///">XYZ.com</a> doesn't exactly work either. So, the easiest solution is <a href='http://www.xyz.com/'>XYZ.com</a> But that's tedious if you have a long page of code, including links, images, and anything else that refers to a file on the server.

    Anyway, where possible, I recommend the first scenario. It's the cleanest/easiest to read/edit. The second is the next best alternative, if it's necessary. I'd say, use the third with caution and only if you had to, as from the sound of it, that would only work in very specific situations, and you'd have to be very careful to make sure it's all working right. It's not worth it if it's not necessary. I wouldn't suggest it if you're not advanced enough to know for sure that you're doing things right (erm, like me, but anywho). Sadly, I can't take the credit for all this, and he didn't want the credit, so, I credit "Unknown" for this and leave it at that. If I've misunderstood anything, it's most likely in regards to the third scenario. I wouldn't have any idea under what specific conditions it would work - I just know for sure that it won't work when wrapped inside the echo ""; command.

IMN logo majestic logo threadwatch logo seochat tools logo