Jump to content

Archived

This topic is now archived and is closed to further replies.

Guest

Changing stylesheet.css with script

Recommended Posts

Guest

I have been working all day to create a php script to replace my shell script which takes the color selected from mycolor.php file. The mycolor.php allows me to select the color and then created the color number. I am passing that to my shell script and thus substituting the color with the one from mycolor.php.

 

I have the mystyle.php code working just fine as long as I am hard coding the color in

$newcontents = str_replace("#bbc3d3","$color1", $contents);

 

I have the $color output from the form and can print it out to my screen and also to update the file I call color.txt. But when I try

$newcontents = str_replace($curcolor, $color1, $contents);
it does not work.

 

This is my first PHP script so do not laugh. Here it is. Can anyone help?

<?php

// A stylesheet.css modify script

// read $color1 from the color.html file



$path = "."; // location of directory

$filename = "stylesheet.css";    // filename

$colorfile = "color.txt";



// Read the color file to get our current color

$fd = fopen ("$colorfile", "r");        // open the file for reading

$curcolor = fread ($fd, filesize($colorfile));

fclose ($fd);                           // close the file



// get contents of a file into a $contents string

$fd = fopen ("$path/$filename", "r");   // open the file for reading

$contents = fread ($fd, filesize ($filename));

fclose ($fd);                           // close the file



// We substitute the default color with our selected color

$newcontents = str_replace("#bbc3d3","$color1", $contents);

//$newcontents = str_replace($curcolor, $color1, $contents);



// Send our output back to the browser for testing

echo "$curcolor / $color1 <br>";

echo "<pre>";     //- use the <PRE> tag to view for testing

//echo $contents; //- uncomment for testing

echo $newcontents; //- This is the new file



// Commented to keep from overwriting the files. Currently the $filename is

// not getting written with the $newcontents but the $colorfile is writing

// the $color1, thus updating



// Now we can write our new color into the file with the $newcontents

//$fd = fopen("$filename",'w');

//fputs($fd, $newcontents);

//fclose($fd);



// Store the current color value in a file to allow us to change it later

//$fd3 = fopen("$colorfile",'w');

//fputs($fd3, $color1);

//fclose($fd3);

?>

 

-Al

Share this post


Link to post
Share on other sites
Guest

I used

$var = substr("$curcolor",0, 7);

$newcontents = str_replace($var, $color1, $contents);

I guess by setting $var I could use it in the str_replace.

 

Any help on writing the script a little cleaner would be helpful.

 

Thanks

 

-Al

Share this post


Link to post
Share on other sites

Can't understand...exactly why you want to modify the style sheet with PHP instead of just editing it yourself?

Share this post


Link to post
Share on other sites
Guest

If you see the posts concerning this area you will understand.

 

There are others that have mad them contributions that change the apperance of the catalog. Al I am doing is creating a form that allows me to substite values in the stylesheet.css without having to edit bby hand.

 

I stayed up most of the night and have it working, just need to clean up the code.

 

I have a customer demoing it at http://heretohost.com/catalog/mycolor.php.

It will bring up the catalog default page once complete.

 

-Al

Share this post


Link to post
Share on other sites

Now that is slick ... :D

 

Wouldn't happen to want to share the code for that would you?

Share this post


Link to post
Share on other sites
Guest

I would like to share it (even though it is rough).

 

Would you like to help clean it up to offer it as a contribution?

 

I have 2 php files and then a color.txt that I store the current color in.

 

How can I get the code to you to view?

 

-Al

Share this post


Link to post
Share on other sites

I'd be happy to look at it and see about making it pretty ... :D

 

Send it to: osCOMMMERCE @ WebMakers.com

 

NOTE: there are spaces in that email address above, as I hate the spamm from those forum spamm searchers.

 

Thanks!

Share this post


Link to post
Share on other sites

You might want to look at eval() in php... it's ideal for templating sort of stuff. It basically evaluates any file as php...

 

Regards,

Mattice


"Politics is the art of preventing people from taking part in affairs which properly concern them"

Share this post


Link to post
Share on other sites

Al,

 

Hey. Glad to see that you are getting a little deeper into the php world. Lot's to learn huh? Well, just saw your post and wanted to say hi.

 

Congratulations on your first script,

-Chris


Chris Sullivan

Share this post


Link to post
Share on other sites

×