473,231 Members | 1,755 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,231 software developers and data experts.

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><font size='1'>"
$endstyle ="</b></i></font>"
$s = array($style,$endstyle)
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

Jul 17 '05 #1
5 1900
.oO(Dynamo)
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><font size='1'>"
$endstyle ="</b></i></font>"
$s = array($style,$endstyle)
echo $s[0] . "I want my font in bold italic and size 1" . $s[1]

does this not do the same as style classes?
No. You use old deprecated stuff like the font-element for example. This
has nothing to do with CSS.
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?
No.
Why use 2 programming languages when it can be done in 1?


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
Jul 17 '05 #2
Dynamo wrote:
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><font size='1'>"
$endstyle ="</b></i></font>"
$s = array($style,$endstyle)
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

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
Jul 17 '05 #3
"Dynamo" <Dy***********@newsguy.com> wrote in message
news:co********@drn.newsguy.com...
Surely if I write something in PHP like

$style = "<b><i><font size='1'>"
$endstyle ="</b></i></font>"
$s = array($style,$endstyle)
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?
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.
Why use 2 programming languages when it can be done in 1?


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.
Jul 17 '05 #4
Dynamo wrote:
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><font size='1'>"
$endstyle ="</b></i></font>"
$s = array($style,$endstyle)
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?


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 - sp**@koivi.com
http://www.koivi.com
Jul 17 '05 #5
Dynamo wrote:
Hi again,

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


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.
Jul 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: David MacQuigg | last post by:
I have what looks like a bug trying to generate new style classes with a factory function. class Animal(object): pass class Mammal(Animal): pass def newAnimal(bases=(Animal,), dict={}):...
13
by: arreeess | last post by:
i wont used three styles in the element of a list; i have does so: <ul> <li> ............................. </li> first style <li> <p> .....................</p> </li> 2° style <li> <p...
9
by: lkrubner | last post by:
How do I get all the div's on a page? I realize in IE I can use document.all. For the other browsers, I need to get an array of all the divs on the page. getElementByTagName()?????
3
by: Kalle Anke | last post by:
I'm confused by the concepts of old-style vs new-style classes, I've read most of the documents I found about this but it doesn't "click". Probably because I wasn't around before 2.2. Anyway,...
38
by: looping | last post by:
For Python developers around. >From Python 2.5 doc: The list of base classes in a class definition can now be empty. As an example, this is now legal: class C(): pass nice but why this...
1
by: Armin Gajda | last post by:
Hi, I have the following problem: An input field get a border assigned by a style class (e.g. 2px solid red). When the field gets the focus, we set the border to green. element.style.border...
13
by: stephenpas | last post by:
We are trying to monkey-patch a third-party library that mixes new and old-style classes with multiple inheritance. In so doing we have uncovered some unexpected behaviour: <quote> class Foo:...
3
by: Michellevt | last post by:
Hi I am working on a project (for college) and wondered if anyone can help me with my problem. In the project we are not allowed to make use of any "style" attributes but "class" attributes...
5
by: Nathan Sokalski | last post by:
I have css that would normally be placed in style tags in the header of the Master page that I want to add programmatically for a specific Web Content Form (the *.aspx page). How do I do this for a...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.