By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,304 Members | 1,242 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,304 IT Pros & Developers. It's quick & easy.

any php/css parsers out there?

P: n/a
Are there any php/css parsers out there?
I looked in the Zend Framework and Pear both, and didn't find one.
All the stuff that comes up on Google (for css editing) are applications.

It would be more than handy if you could read a css file into a data
structure, and then build forms to update it, and the re-write the file
on save (hidden behind a password barrier).
Aug 14 '08 #1
Share this Question
Share on Google+
18 Replies


P: n/a
osnot wrote:
Are there any php/css parsers out there?

Yes, we can all read PHP code and most of us are also good at reading CSS.

What is it you really want?
Aug 14 '08 #2

P: n/a
Dikkie Dik wrote:
osnot wrote:
>Are there any php/css parsers out there?


Yes, we can all read PHP code and most of us are also good at reading CSS.

What is it you really want?
I thought I said it in the original post: if you could transform a
css file into a data structure, then you could manipulate it with
forms, and then write it back out again. A parser that produced
a data structure could be the basis of a web-app css editor.

I wrote one that works. But it relies on the css being in a
particular format (curly brackets on a separate line, etc).
I suppose I could slurp the file into a string and then use
regular expressions to force the format I need.

A css file to data structure utility would (it seems to me) be a
handy thing.
Aug 14 '08 #3

P: n/a
osnot wrote:
Dikkie Dik wrote:
>osnot wrote:
>>Are there any php/css parsers out there?


Yes, we can all read PHP code and most of us are also good at reading
CSS.

What is it you really want?

I thought I said it in the original post: if you could transform a
css file into a data structure, then you could manipulate it with
forms, and then write it back out again. A parser that produced
a data structure could be the basis of a web-app css editor.

I wrote one that works. But it relies on the css being in a
particular format (curly brackets on a separate line, etc).
I suppose I could slurp the file into a string and then use
regular expressions to force the format I need.

A css file to data structure utility would (it seems to me) be a
handy thing.
Yes, I agree - this would be a handy thing to have. Unfortunately, I
don't know of any out there.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Aug 14 '08 #4

P: n/a
Jerry Stuckle wrote:
osnot wrote:
>Dikkie Dik wrote:
>>osnot wrote:
Are there any php/css parsers out there?
Yes, we can all read PHP code and most of us are also good at reading
CSS.

What is it you really want?

I thought I said it in the original post: if you could transform a
css file into a data structure, then you could manipulate it with
forms, and then write it back out again. A parser that produced
a data structure could be the basis of a web-app css editor.

I wrote one that works. But it relies on the css being in a
particular format (curly brackets on a separate line, etc).
I suppose I could slurp the file into a string and then use
regular expressions to force the format I need.

A css file to data structure utility would (it seems to me) be a
handy thing.

Yes, I agree - this would be a handy thing to have. Unfortunately, I
don't know of any out there.
That should'nt be very difficult to do. First minify the css and then
use preg_match_all to match all style definitions and convert them to an
array.

If there's really need for such an feature i will think to add that to
my css minifier.

Joe
Aug 14 '08 #5

P: n/a
Joe Scylla wrote:
>
If there's really need for such an feature i will think to add that to
my css minifier.

Joe
That would be very useful.
If you had:

#wrapper{
width: 90%;
}

then, in a form you could have a widget:
<input type="text" name="_#wrapper__width">

On post you could loop through all the widgets
and update the data structure ( a hash of css block names like #wrapper
returns a class that contains the contained css somehow ),
and then rewrite the file. Each time you clicked the save button you
could view the results on a page that uses that css. Seems like
every "framework" or "cms" in existence would want this.

Aug 14 '08 #6

P: n/a
osnot wrote:
Joe Scylla wrote:
>>
If there's really need for such an feature i will think to add that to
my css minifier.

Joe

That would be very useful.
If you had:

#wrapper{
width: 90%;
}

then, in a form you could have a widget:
<input type="text" name="_#wrapper__width">

On post you could loop through all the widgets
and update the data structure ( a hash of css block names like #wrapper
returns a class that contains the contained css somehow ),
and then rewrite the file. Each time you clicked the save button you
could view the results on a page that uses that css. Seems like
every "framework" or "cms" in existence would want this.
Since I'm just finishing rewriting my CMS to PHP I'd like to take
this thread a bit off the php topic and discuss the utility of that.

The beautiful thing about a CMS is that it lets you keep a uniformity
throughout the site. Anyone who has seen a site edited ad hoc can see
the benefit of that.

Now, what you would have is individual stylesheets embedded in each
page, and your users would be able to change individual properties, like
width in your example. Changing an individual property is seldom useful
to a user, although it is to a designer. It's usually several properties
that a user needs to change at the same time.

What I find useful is to take one of these blocks like your wrapper
and change the classname from one predefined class, to another. That
eliminates user "errors" and lets the user change several things in a
coordinated way.

Jeff
>
Aug 15 '08 #7

P: n/a
Jeff wrote:
>
...snipped...

Since I'm just finishing rewriting my CMS to PHP I'd like to take this
thread a bit off the php topic and discuss the utility of that.

The beautiful thing about a CMS is that it lets you keep a uniformity
throughout the site. Anyone who has seen a site edited ad hoc can see
the benefit of that.

Now, what you would have is individual stylesheets embedded in each
page, and your users would be able to change individual properties, like
width in your example. Changing an individual property is seldom useful
to a user, although it is to a designer. It's usually several properties
that a user needs to change at the same time.

What I find useful is to take one of these blocks like your wrapper
and change the classname from one predefined class, to another. That
eliminates user "errors" and lets the user change several things in a
coordinated way.

Jeff
You may want ot check out the version 1.0.1.b2 of my css-minifier
(http://code.google.com/p/cssmin/). I included a function to convert a
string containing style definitions into a array structure (and convert
this array structure into a style definition)

Example Output:

<code>
[0] =Array
(
[keys] =Array
(
[0] =a
)
[styles] =Array
(
[color] =#4e5aa7
[text-decoration] =none
)
)
[1] =Array
(
[keys] =Array
(
[0] =a:hover
)
[styles] =Array
(
[color] =#4e5aa7
[text-decoration] =underline
)
)
[2] =Array
(
[keys] =Array
(
[0] =body
[1] =th
[2] =td
)
[styles] =Array
(
[font-family] =Verdana,sans-serif
[font-size] =11px
[line-height] =16px
[margin] =0px
[padding] =0px
[vertical-align] =top
)
)
</code>

Joe
Aug 15 '08 #8

P: n/a
Jeff wrote:
>
Now, what you would have is individual stylesheets embedded in each
page, and your users would be able to change individual properties, like
width in your example. Changing an individual property is seldom useful
to a user, although it is to a designer. It's usually several properties
that a user needs to change at the same time.

No no no. That's not what I had in mind. I'm thinking of an
administration GUI behind a password barrier. This is not for the user,
but for the site owner only. I was talking about modifying the global
css files.

Aug 15 '08 #9

P: n/a
On Aug 14, 12:39 pm, osnot <davidos...@not.netwrote:
Are there any php/css parsers out there?
I looked in the Zend Framework and Pear both, and didn't find one.
All the stuff that comes up on Google (for css editing) are applications.

It would be more than handy if you could read a css file into a data
structure, and then build forms to update it, and the re-write the file
on save (hidden behind a password barrier).
There isn't an 'official' or at least popular CSS parser that I'm
aware of, I'm afraid. Fortunately, CSS follows a relativity simple
format so building a parser of your own shouldn't be too difficult.
The basic format is:

<selector>
{
<property>: <value(optional <!qualifier>);
<property>: <value(optional <!qualifier>);
....
}
<selector>
.....

As in HTML, white space isn't significant. There are a few things
you'll need to watch for, like @rules, optional property qualifiers
like !important, etc, but building a parser of acceptable quality
shouldn't be tremendously taxing.
Aug 15 '08 #10

P: n/a
Gordon wrote:
On Aug 14, 12:39 pm, osnot <davidos...@not.netwrote:
>Are there any php/css parsers out there?
I looked in the Zend Framework and Pear both, and didn't find one.
All the stuff that comes up on Google (for css editing) are applications.

It would be more than handy if you could read a css file into a data
structure, and then build forms to update it, and the re-write the file
on save (hidden behind a password barrier).

There isn't an 'official' or at least popular CSS parser that I'm
aware of, I'm afraid. Fortunately, CSS follows a relativity simple
format so building a parser of your own shouldn't be too difficult.
The basic format is:

<selector>
{
<property>: <value(optional <!qualifier>);
<property>: <value(optional <!qualifier>);
....
}
<selector>
....

As in HTML, white space isn't significant. There are a few things
you'll need to watch for, like @rules, optional property qualifiers
like !important, etc, but building a parser of acceptable quality
shouldn't be tremendously taxing.
But it can get more complicated real quickly, i.e.

col1, col2, col3 {
(properties)
}

col1 {
(properties)
}

and so on. Trying to sort all of those into their respective selectors
can be difficult. So can the rule sets for the selectors and their
possible options.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Aug 15 '08 #11

P: n/a
..oO(Gordon)
>On Aug 14, 12:39 pm, osnot <davidos...@not.netwrote:
>Are there any php/css parsers out there?
I looked in the Zend Framework and Pear both, and didn't find one.
All the stuff that comes up on Google (for css editing) are applications.

It would be more than handy if you could read a css file into a data
structure, and then build forms to update it, and the re-write the file
on save (hidden behind a password barrier).

There isn't an 'official' or at least popular CSS parser that I'm
aware of, I'm afraid.
It should be possible to generate parsers with the rules described in
the CSS spec.

http://www.w3.org/TR/CSS21/grammar.html
>Fortunately, CSS follows a relativity simple
format so building a parser of your own shouldn't be too difficult.
The basic format is:

<selector>
{
<property>: <value(optional <!qualifier>);
<property>: <value(optional <!qualifier>);
....
}
<selector>
Selectors and shorthand properties can become quite difficult.

Micha
Aug 15 '08 #12

P: n/a
osnot wrote:
Jeff wrote:
>>
Now, what you would have is individual stylesheets embedded in each
page, and your users would be able to change individual properties,
like width in your example. Changing an individual property is seldom
useful to a user, although it is to a designer. It's usually several
properties that a user needs to change at the same time.


No no no. That's not what I had in mind. I'm thinking of an
administration GUI behind a password barrier. This is not for the user,
but for the site owner only. I was talking about modifying the global
css files.
Same caveats apply. Plus you are asking your user (the site owner) to
make CSS changes he really doesn't understand and won't see until (s)he
reloads the page. I'd suggest that you at least use some DOM methods to
view the changes as they are being made, that is fairly trivial to do.
For that matter, you can read the rules using your browsers DOM and list
them in a form using javascript.

It's still crazy to edit individual rules and the potential for
creating an uncontrollable mess is great. Changing classnames or class
definitions gives your users (the site owner) control with less disaster
potential.

Jeff

>
Aug 15 '08 #13

P: n/a
Jeff wrote:
It's still crazy to edit individual rules and the potential for
creating an uncontrollable mess is great. Changing classnames or class
definitions gives your users (the site owner) control with less disaster
potential.

Jeff
Bad idea to have a form-based CSS editor?
Maybe.

I have a small files-based CMS that makes fckeditor
available to the site owner. I never use it. I edit html fragments with
vi perl sed and bash. But the site owners
love it. Mom and pop store owners, political candidates,
artists, university departments and research groups love to
edit their own sites. Dreamweaver makes a mess.

But a cms gives them access to bits and pieces that get stuffed
into a coherent framework. They (my customers) all clamor for a css
editor. It could easily have some fall-back defaults, plus a list
of previously saved and named states to revert to.

When your customers clamor for something, they're telling you something.

Aug 15 '08 #14

P: n/a
osnot wrote:
Jeff wrote:
> It's still crazy to edit individual rules and the potential for
creating an uncontrollable mess is great. Changing classnames or class
definitions gives your users (the site owner) control with less
disaster potential.

Jeff

Bad idea to have a form-based CSS editor?
Maybe.

I have a small files-based CMS that makes fckeditor
available to the site owner. I never use it. I edit html fragments with
vi perl sed and bash. But the site owners
love it. Mom and pop store owners, political candidates,
artists, university departments and research groups love to
edit their own sites. Dreamweaver makes a mess.
I have no disagreement there.
>
But a cms gives them access to bits and pieces that get stuffed
into a coherent framework. They (my customers) all clamor for a css
editor. It could easily have some fall-back defaults, plus a list
of previously saved and named states to revert to.

When your customers clamor for something, they're telling you something.
That's fine, but what are you giving them? Lets look at the web 2.0
curved boxes and styled lists. You can't do any of that by changing a
property or two, but you can easily do that by either changing a class
or classname. Otherwise they have little practical control other than
font properties and colors. You can't change a width without considering
what it does elsewhere and you usually can't change a float from left to
right without adjusting margins/padding if you want it to look right. To
this day, there are still issues of what different browsers will do and
at different font sizes. I'd never want a user to willy nilly be able to
change every property in a stylesheet.

I've written more than one online CSS editor through the years, some
of which were point and click, and that's the conclusion I've reached.

Depending on how you design your html and CSS you could give all your
users the same basic set of options.

YMMV.

Jeff
>
Aug 15 '08 #15

P: n/a
REsite owners and complex CSS editing

Yes of course you are right about this: there is only so
much a user could do.

1) For one thing I think I'm talking about a niche subset of customers
and websites. High dollar corporate websites have an IT team anyway.
User-editing is not on the table.

2) Letting users occasionally get themselves into trouble tends to
bring them back to you in a more manageable form. Suddenly you
are not only the magician, you are the hero of the day.

3) The CSS editor I'm working has a feature frighteningly like
Dreamweaver: some blocks are marked "editiable" with "/* edit yes */"
while other blocks are marked with "/* edit no */"

There is no harm (in my view) in letting customers play with H1 colors
and border widths. Stacked image fragments that make rounded courners,
dynamic-looking tabs etc? That stuff has to be off customer limits.

There is a strong niche market for what I proposed. That I know.
They ask for it constantly (why can't I change the heading color, etc).
Is it a bad idea in the long run?

Time will tell. I see it coming. I'll have my own version online
by the end of the month.
Aug 16 '08 #16

P: n/a
osnot wrote:
REsite owners and complex CSS editing

Yes of course you are right about this: there is only so
much a user could do.

1) For one thing I think I'm talking about a niche subset of customers
and websites. High dollar corporate websites have an IT team anyway.
User-editing is not on the table.
I'm constantly amazed at the people that I think should have html/css
skills and the miserable stuff they churn out. On the other hand, people
I don't suspect have turned out some neat stuff in a CMS.
>
2) Letting users occasionally get themselves into trouble tends to
bring them back to you in a more manageable form. Suddenly you
are not only the magician, you are the hero of the day.
You've got a point there!
>
3) The CSS editor I'm working has a feature frighteningly like
Dreamweaver: some blocks are marked "editiable" with "/* edit yes */"
while other blocks are marked with "/* edit no */"
I used to get templates written in Dreamweaver, abysmal stuff. Never
checked out the CSS though. Seems scary!
>
There is no harm (in my view) in letting customers play with H1 colors
and border widths.
Well, it depends on how you have the html laid out and whether you are
in standards mode. A wider border/increased padding adds to the
container width. If you do this, nest your containers and set the width
with the outer and the padding/borders on the inner.

As far as colors go, I keep them in the color scheme, whether it's
triad, monochromatic or some kind of split complimetary. Guys, in
particular, don't get color schemes. I give them about 50 choices in the
scheme and generate the colors programatically. It's a little tough for
a programmer to initially grasp, but there really are some standard
design rules and you can code them once you understand them.

Stacked image fragments that make rounded courners,
dynamic-looking tabs etc? That stuff has to be off customer limits.
I'm doing it now as client settable. Just use descendants. For that
matter, set everything you can as descendants.
>
There is a strong niche market for what I proposed. That I know.
They ask for it constantly (why can't I change the heading color, etc).
Is it a bad idea in the long run?
Be prepared for some tacky looking stuff!
>
Time will tell. I see it coming. I'll have my own version online
by the end of the month.
Good luck!

Jeff
>
Aug 16 '08 #17

P: n/a
Message-ID: <Sd******************************@earthlink.comfro m Jeff
contained the following:
Be prepared for some tacky looking stuff!
It's amazing how tacky the site can become even if you only let them
edit text. (said he, from bitter experience)

--
Geoff Berrow 0110001001101100010000000110
001101101011011001000110111101100111001011
100110001101101111001011100111010101101011
http://slipperyhill.co.uk - http://4theweb.co.uk
Aug 16 '08 #18

P: n/a
Geoff Berrow wrote:
Message-ID: <Sd******************************@earthlink.comfro m Jeff
contained the following:
> Be prepared for some tacky looking stuff!

It's amazing how tacky the site can become even if you only let them
edit text. (said he, from bitter experience)
;)

Jeff
Aug 16 '08 #19

This discussion thread is closed

Replies have been disabled for this discussion.