GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 14-Jul-2003, 10:10
Mary Mary is offline
New Member
 
Join Date: Jul 2003
Posts: 3
Mary is an unknown quantity at this point
Unhappy

Reading File, Arrays, Editing File


Without going into all the whys... here's what I am wanting to do, but can't figure out how to do it.

I want to make a user-friendly way to edit a css file, using a form and php.

Now, I know that it would be very easy to just create a vars file which the form writes to, and then grab the vars from inline styles on the page.

However, that does keep the css from caching on a user machine, which doesn't really appeal to me.

So, I am trying to figure out how to do edit the external css file itself, since that would not happen all that often (but often enough for someone to completely screw up the css file). I don't want/need all the values to be edited, just certain things like colours.

I thought It might be done by reading the file into an array, and making a relational array. But the file thingy only reads it into one big array - I'd like it to read each css selector into a separate array, with each css attribute being the key, and each css value the value.

Try as I may I can't figure it out, I don't even have any assemblance of code working at all (can't get past reading up on relational vs multi-dimensional arrays).

Am I making this too hard? Is there some magic way I am missing (like nl2br - ah the sweetness of it all)? Or something I've overlooked?

All the tutorials on arrays I could find were not very helpful to me in this case, and I am still a newbie (or at least not a guru by any stretch of the imagination).

I would greatly appreciate it if someone would at least point me in the right direction, so I can hopefully learn this stuff. Or, do I have it take it like an adult, it can't be done, and try not to cry to loudly?

  #2  
Old 14-Jul-2003, 10:29
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough
Let me see if I understood you well...

You have an external css file that you want to edit using a web form and PHP?
  #3  
Old 14-Jul-2003, 10:33
Mary Mary is offline
New Member
 
Join Date: Jul 2003
Posts: 3
Mary is an unknown quantity at this point
Yes. I did say I didn't want to go into all the whys, but I guess I'll have to. It's for someone else to edit the non-essential codes (for colours etc), without giving access to important css stuff (that keeps invariably getting screwed up/deleted).

The idea being, I can also put in safeguards like not adding any funny characters, like periods which make IE go insane.

Edit:
Let me guess, this can't be done, can it?
  #4  
Old 14-Jul-2003, 10:42
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough
Contrary to what you thought I wasn't asking you why! I was confirming that I had understood your question... anyways; anything is possible with PHP - I seem to have said that at least twice this week

If you want to do this, you might probably want to put these values in some sort of a database, text-file or a regular database.

Of course I haven't given it much thought so there might be a 'smarter' way yet.

Let's talk about text-files - you'd probably want to store these values as an array (using PHP's serialize() function) or as an ini set (using PHP's parse_ini_file() function).

What do you think?

By the way Mary, welcome to GIDForums™
  #5  
Old 15-Jul-2003, 02:14
Garth Farley Garth Farley is offline
Awaiting Email Confirmation
 
Join Date: May 2002
Location: Ireland
Posts: 638
Garth Farley is a jewel in the roughGarth Farley is a jewel in the roughGarth Farley is a jewel in the rough
Another possible way of doing this, is to create a template css file, which will have special placeholders where you want to stick in the colours.

Example from this page's CSS:
Code:
BODY { SCROLLBAR-BASE-COLOR: [SCROLL1]; SCROLLBAR-ARROW-COLOR: [SCROLL2]; } A:link, A:visited, A:active { COLOR: [A_COLOR]; } A:hover { COLOR: [A_HOVER]; }

So in PHP offer a dropdown list of colors for each thing (Scrollbar basse & Arrow, A link color...). Then on subbmit, open this file in PHP & stick in a variable, then using some simple enough str_replace statements, you can replace each placeholder with it's colour, and then write it out to another file.

It's not very flexible though, but it does keep the important CSS code out of the punters reach, and you can validate everything before you write to the CSS file.

Garth Farley
 
 

Recent GIDBlogProblems with the Navy (Enlisted) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Reading from file jmenendezr C++ Forum 2 26-Feb-2006 16:00
How Do i get php to find out the file type of a file for me? viperman95833 MySQL / PHP Forum 2 08-Mar-2003 09:48

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 08:34.


vBulletin, Copyright © 2000 - 2010, Jelsoft Enterprises Ltd.