Reputation: 590
My project is in PHP, I need change the image folder name in css files dynamically,
ie.,
# all.css file
.html{
background: url(../img/login.gif) no-repeat scroll 0 -36px;
.....
}
I need change the folder name "img" to "image" or "styleimg" etc., depends on the templatewise. How is it possible with the php file ?
Upvotes: 2
Views: 545
Reputation: 2224
Use PHP to serve out the CSS. Use the header() to set the content type as text/css, output most of the CSS outside of the tag (but after setting the header of course). Find out the selected template in this PHP, assign the required directory name to a variable, say, $imgloc.
Then, at the lines where you require to output the image name, do something like this:
background: url(../<?= $imgloc ?>/login.gif) no-repeat scroll 0 -36px;
Upvotes: 2
Reputation: 648
<?php
$file = xyz.css;
$handle = @fopen($file, "r"); // Open file form read.
$line_match = "background: url(../img/login.gif) no-repeat scroll 0 -36px;\n";
$toThis = "background: url(../img/new_login_image.gif) no-repeat scroll 0 -36px;\n";
if ($handle) {
while (!feof($handle)) // Loop til end of file.
{
$buffer .= fgets($handle, 4096); // Read a line.
if ($buffer == $line_match) // Check for string.
{
echo "$buffer"; // If not string show contents.
} else {
$buffer .= $toThis; // If string, change it.
echo "$buffer"; // and show changed contents.
}
}
$Handle = fopen($file, 'w');
$Data = $buffer;
fwrite($Handle, $Data);
fclose($handle); // Close the file.
}
?>
maybe drop the \n im from vars $linematch and $toThis not sure off hand! - try both.
Upvotes: 0