![]() |
|
#1
|
|||
|
|||
Reading File, Arrays, Editing FileWithout 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
|
||||
|
||||
|
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? __________________
J de Silva Learning Journal | GIDForums™ | GIDNetwork™ | GIDWebhosts™ | GIDSearch™ |
|
#3
|
|||
|
|||
|
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
|
||||
|
||||
|
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™ __________________
J de Silva Learning Journal | GIDForums™ | GIDNetwork™ | GIDWebhosts™ | GIDSearch™ |
|
#5
|
|||
|
|||
|
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:
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 GIDBlog
Prepping for deployment by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Reading from file | jmenendezr | CPP / 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