Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Use PHP to place a css file link in the header??

  • This topic is empty.
Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #39927
    Blackhawkso
    Member

    Hey everyone

    I’m writing a small PHP script for someone who will just use a PHP include to run the script. The thing is that I need to supply some CSS for the script to use when it runs. Does anyone know how I can use PHP to automatically place the link tag with the link for the CSS file into the head section of the page that calls it because I really don’t want to have to use inline CSS as that is messy.

    Cheers everyone.

    #110393
    chrisburton
    Participant

    @blackhawkso Not sure why you’d want to do this. You can just put what I have below in the head section. You wouldn’t need to include it unless I’m not understanding your issue.

    ``

    #110397
    Blackhawkso
    Member

    @ChristopherBurton Hey Chris thanks for a reply.

    The issue is that I writing a file for the guy called calendar.php, now he can use this file anywhere he wants in any other script by using a PHP include. Now I could make the outputted html from the PHP script have a head tag etc etc so that the link for the CSS file goes inside a head tag like it should but I don’t know the page that he is going to use the script on and I don’t want to insert extra html tags into the middle of his page and make his code messy, so what I want to do is if he had a file called lets say index.php and in that file he used I would want to place the link for the CSS file into the head tag of the index.php page. Clear as mud? lol

    #110398
    chrisburton
    Participant

    @blackhawkso That is understandable but why don’t you ask him where he is going to use it? Shouldn’t you know as you’re developing it for him? You could also use an if statement. Like so:

    if page is index.php

    echo stylesheet

    else

    do nothing

    #110399
    Blackhawkso
    Member

    @ChristopherBurton I was just asked to throw together a simple calendar script for him as he has a big job on (I don’t know what the job is) and he is running out of time and I owed him a favour.

    #110400
    chrisburton
    Participant

    @blackhawkso You can either attach it to every page or you can write an if else statement. If the css file isn’t large, don’t worry about it.

    Updated:

    if ($url == “http://www.sample.com/test.php”) {
    echo ‘‘;
    };

    #110404
    Blackhawkso
    Member

    @ChristopherBurton right ok cheers

    #110403
    chrisburton
    Participant

    @blackhawkso Check the code again above. It seemed to have been cut off previously.

    #110478
    kevinvance
    Participant

    You don’t need the else { } in this case, though. If it doesn’t meet the condition of the if, it will already do nothing.

    #110486
    Dhanishta
    Member

    In the above link, you can attach the if part to all pages, but you just remove the else part because it won’t do anything even if that if part is failed, specifically no need to mention.

    #110501
    chrisburton
    Participant

    I didn’t know that. Thanks for the info @kevinvance @Dhanishta. I updated the code above.


    @blackhawkso
    Let us know if this solved your problem.

Viewing 11 posts - 1 through 11 (of 11 total)
  • The forum ‘Back End’ is closed to new topics and replies.