Style class css or PHP?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dynamo

    Style class css or PHP?

    Hi again,

    Having had a little experience of HTML and style classes but only a limited
    knowledge of PHP perhaps somebody can tell me the pros and cons of the
    following.

    Surely if I write something in PHP like

    $style = "<b><i><fon t size='1'>"
    $endstyle ="</b></i></font>"
    $s = array($style,$e ndstyle)
    echo $s[0] . "I want my font in bold italic and size 1" . $s[1]

    does this not do the same as style classes? Taking it one step further, if I
    write all of the styles in a script called styles.php and include it in all of
    my php pages is that not the same as having a .css file?

    Why use 2 programming languages when it can be done in 1?

    Comments please

  • Michael Fesser

    #2
    Re: Style class css or PHP?

    .oO(Dynamo)
    [color=blue]
    >Having had a little experience of HTML and style classes but only a limited
    >knowledge of PHP perhaps somebody can tell me the pros and cons of the
    >following.
    >
    >Surely if I write something in PHP like
    >
    >$style = "<b><i><fon t size='1'>"
    >$endstyle ="</b></i></font>"
    >$s = array($style,$e ndstyle)
    >echo $s[0] . "I want my font in bold italic and size 1" . $s[1]
    >
    >does this not do the same as style classes?[/color]

    No. You use old deprecated stuff like the font-element for example. This
    has nothing to do with CSS.
    [color=blue]
    >Taking it one step further, if I
    >write all of the styles in a script called styles.php and include it in all of
    >my php pages is that not the same as having a .css file?[/color]

    No.
    [color=blue]
    >Why use 2 programming languages when it can be done in 1?[/color]

    CSS is no programming language. But even using CSS and printing it out
    like above makes no sense, because it would be embedded in all HTML
    pages instead of stored in an external file (that's how it should be).

    Use PHP to print out HTML and maybe CSS (of course you can generate a
    CSS file with PHP), but don't mix it like above.

    Micha

    Comment

    • alexandre damiron

      #3
      Re: Style class css or PHP?

      Dynamo wrote:
      [color=blue]
      > Hi again,
      >
      > Having had a little experience of HTML and style classes but only a limited
      > knowledge of PHP perhaps somebody can tell me the pros and cons of the
      > following.
      >
      > Surely if I write something in PHP like
      >
      > $style = "<b><i><fon t size='1'>"
      > $endstyle ="</b></i></font>"
      > $s = array($style,$e ndstyle)
      > echo $s[0] . "I want my font in bold italic and size 1" . $s[1]
      >
      > does this not do the same as style classes? Taking it one step further, if I
      > write all of the styles in a script called styles.php and include it in all of
      > my php pages is that not the same as having a .css file?
      >
      > Why use 2 programming languages when it can be done in 1?
      >
      > Comments please
      >[/color]
      You should, anytime it's possible, let let the client manage the final
      output (by js, dom, dhtml, and css), and keep php for operation that can
      be only done on your server. Servers are often over-charged, while
      people own powerful PCs and don't use that power. More important, using
      css will ease your styles manipulation and lighten your pages. Don't
      worry about the number of programming languages, there is always many
      solutions to one web task. This is just the history of the web and it is
      perfect like that. Just choose the best option for your task.

      Cheers,

      Alexandre Damiron

      Comment

      • Joshua Beall

        #4
        Re: Style class css or PHP?

        "Dynamo" <Dynamo_member@ newsguy.com> wrote in message
        news:cojq8t0qdk @drn.newsguy.co m...[color=blue]
        > Surely if I write something in PHP like
        >
        > $style = "<b><i><fon t size='1'>"
        > $endstyle ="</b></i></font>"
        > $s = array($style,$e ndstyle)
        > echo $s[0] . "I want my font in bold italic and size 1" . $s[1]
        >
        > does this not do the same as style classes? Taking it one step further, if
        > I
        > write all of the styles in a script called styles.php and include it in
        > all of
        > my php pages is that not the same as having a .css file?[/color]

        Well, you could effectively do the same thing (make text bold, italic, and
        small) different ways. But it's not the same thing, per se, because one of
        the advantages of CSS is that you are able to get a lot of the markup out of
        your document body, and into an external stylesheet. This means that the
        user only has to download the stylesheet once. If you have all the styles
        directly embedded in every document, it has to be downloaded for every
        request - it can't be separated out and cached by the browser.

        Also, I think you will find that CSS provides some things that you cannot do
        with straight HTML tags. For instance, what if you wanted to float a block
        of text along the righthand side, with a dotted gray border and a 10px
        margin on the left and bottom? What tags would you use for that.
        [color=blue]
        > Why use 2 programming languages when it can be done in 1?[/color]

        CSS isn't really a programming language... I'm not even sure what you'd call
        it. But it's more like HTML. It's a descriptive language; it doesn't
        execute, nor is it capable of executing. It only describes information.

        I gave 2 reasons above. 2 more:

        1) You will wind up with horrible namespace pollution as your number of
        "classes" grow. Unless you store them all in an array, which can make it
        cumbersome to embed the tags in a string.
        2) The unnecessary memory usage required to generate and store all the
        "classes" for every page.


        Comment

        • Justin Koivisto

          #5
          Re: Style class css or PHP?

          Dynamo wrote:
          [color=blue]
          > Hi again,
          >
          > Having had a little experience of HTML and style classes but only a limited
          > knowledge of PHP perhaps somebody can tell me the pros and cons of the
          > following.
          >
          > Surely if I write something in PHP like
          >
          > $style = "<b><i><fon t size='1'>"
          > $endstyle ="</b></i></font>"
          > $s = array($style,$e ndstyle)
          > echo $s[0] . "I want my font in bold italic and size 1" . $s[1]
          >
          > does this not do the same as style classes? Taking it one step further, if I
          > write all of the styles in a script called styles.php and include it in all of
          > my php pages is that not the same as having a .css file?
          >
          > Why use 2 programming languages when it can be done in 1?[/color]

          Use CSS. It keeps the code cleaner, and .css files are cached on the
          client side in most cases, where PHP files are not. Save yourself that
          little extra bandwidth - it may end up saving more than that if your
          site was to get a very large surge in traffic (especially the Slashdot
          effect).

          --
          Justin Koivisto - spam@koivi.com

          Comment

          • Mark

            #6
            Re: Style class css or PHP?

            Dynamo wrote:
            [color=blue]
            > Hi again,
            >[/color]
            [color=blue]
            >
            > Why use 2 programming languages when it can be done in 1?[/color]

            i try to keep as much UI as possible out of code. i've almost always
            found that programmers aren't great UI people, so it's nice to be able to
            have some UI person come along (who may be a crappy programmer) and tweak
            the system themselves.

            if you've got a lot of UI in .css files, then the UI gurus can do more of
            their magic. If it's all in PHP code, there's more of a chance they're not
            going to understand it and possibly even bullocks it up ....


            mark.



            --
            I am not an ANGRY man. Remove the rage from my email to reply.

            Comment

            Working...