Inline CSS modification using PHP
Results 1 to 5 of 5

Thread: Inline CSS modification using PHP

  1. #1
    Junior Member
    Join Date
    Sep 2012
    Posts
    2

    Inline CSS modification using PHP

    Hello,
    I am having HTML file with inline CSS available in tags. I want to change background-image, color, fonts etc. using PHP. Is there any option using which I can modify inline CSS easily using PHP? Please help me. Thanks in advance.

  2. #2
    Pedantic Curmudgeon Weedpacket's Avatar
    Join Date
    Aug 2002
    Location
    General Systems Vehicle "Thrilled To Be Here"
    Posts
    21,774
    A bit of context is needed: why are you using inline styles to begin with, instead of an external stylesheet - or even an embedded stylesheet? Both would be easier to work with than generating a page with inline styles, then going back and altering the styles before serving the page.
    THERE IS AS YET INSUFFICIENT DATA FOR A MEANINGFUL ANSWER
    FAQs! FAQs! FAQs! Most forums have them!
    Search - Debugging 101 - Collected Solutions - General Guidelines - Getting help at all

  3. #3
    Junior Member
    Join Date
    Sep 2012
    Posts
    2
    Actually we are building website generator with different options like background color, background image, font color, font size etc. changing using wizard so we are generating runtime css for all & generating HTML out of it. So we need to edit this inline css at the time of publish.

  4. #4
    Settled 4 red convertible dalecosp's Avatar
    Join Date
    Jul 2002
    Location
    Accelerating Windows at 9.81 m/s....
    Posts
    7,623
    vBulletin's approach to this is interesting to me; of course, they've got a lotta brains putting their software together.

    They use "stylevars" which live in the database, along with the associated properties. Their "css.php" file puts them all together according to its parameters, and is called in the HEAD of their HTML.

    That might be too heavyweight for you ... but then again, I could see some benefits to using that or a similar approach in what you're talking about doing...
    /!!\ mysql_ is deprecated --- don't use it! Tell your hosting company you will switch if they don't upgrade! /!!!\ ereg() is deprecated --- don't use it!

    dalecosp "God doesn't play dice." --- Einstein "Perl is hardly a paragon of beautiful syntax." --- Weedpacket

    Getting Help at All --- Collected Solutions to Common Problems --- Debugging 101 --- Unanswered Posts --- OMBE: Office Machines, Business Equipment

  5. #5
    Pedantic Curmudgeon Weedpacket's Avatar
    Join Date
    Aug 2002
    Location
    General Systems Vehicle "Thrilled To Be Here"
    Posts
    21,774
    I'm still not seeing why the styles need to be inline. Even less so, now, since you're building the HTML as well, so you know what classes/ids the various elements will have (and of course the <body> element is going to be the <body> element). The whole point of stylesheets is that the stylesheet can be changed (to provide different backgrounds, fonts, etc.) without changing the HTML. The most compelling expression of this fact would be css Zen Garden.

    Is it that you're generating the page every time, instead of once at publication time and storing the resulting files (during development you'd want the changes to be immediate even if it does mean more processing)? In that case inline styles still wouldn't be necessary; dalecosp describes one way an entire stylesheet can be embedded into the head of the document.

    Finally: even if you are using inline styles when you build the HTML, it strikes me it would be less work putting the right styles in to begin with instead of wrong ones that subsequently have to be replaced.

    However, if you have an HTML document you can load it into a DOM structure and get at the contents of all the various "style" attributes. Of course, you'll need to navigate the DOM to find the attributes you want, and the value of the attribute will be a string that you will still need to parse as a list of CSS declarations.
    Last edited by Weedpacket; 04-05-2013 at 03:38 AM.
    THERE IS AS YET INSUFFICIENT DATA FOR A MEANINGFUL ANSWER
    FAQs! FAQs! FAQs! Most forums have them!
    Search - Debugging 101 - Collected Solutions - General Guidelines - Getting help at all

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •