Is it possible to execute some functions in CSS from outsite file? I have a PHP file (eg. file.php) that contain, image function (eg. image() ). file.php file <?php function image() { $image = image.gif; return $image; } ?> Code (markup): CSS file body { background-image: url([B]image()[/B]); margin-left: 5px; margin-top: 5px; margin-right: 5px; margin-bottom: 2px; } Code (markup): Is it possible to do this? Perhaps we need include or something? I try insert include file.php into CSS file and negative result Need help please. Newbie for CSS here... Thanks for any help. Have a nice day
you can give a php file a CSS header - so browsers view a .php file as a css file. Then in your php file you can do the code above
Unfortunately it's quite inefficient to do that as you'd have to keep downloading the CSS file each image change. I'm guessing you're using this for image rotation? You might want to take a look at: http://alistapart.com/articles/randomizer/ Seperate your style from content and you scripts from style.
Actually I want to implement that script (randomizer) to my CSS style. This script only read one directory. I want choose many directory. In PHP we can use random($folder='foldername'). background-image: url(<?php random($foldername); ?>); Code (markup): Can I make this? Or any another trick? In other question is how to make random image in CSS file. This is my main question. Thanks for your help. Gud lak
Perhaps this is quick and dirty solution: background-image: url(folder01.php); Code (markup): background-image: url(folder02.php); Code (markup): background-image: url(folder03.php); Code (markup): So I have 3 file folder01.php -> $folder = /folderimages01/ folder02.php -> $folder = /folderimages02/ folder03.php -> $folder = /folderimages03/ Can I use another solutions? Thanks
I am not sure, but try this: style.css.php <? header("Cache-Control: no-cache, must-revalidate"); function yourfunction($parametar) { // bla bla bla } ?> .... background-image: url(<?=yourfunction?>); Code (markup):
To make this you need to "teach" your php engine to parse .css as .php files and strip all <?php ?> tags. Add this line into your .htaccess file, so all .css will be pre-processed by php : AddHandler application/x-httpd-php .css Maybe you'll need also send a header "Content-type: text/css;" if css processed by PHP, I don't know.
Thanks for your help. Sound so hard. But I'll try it or perhaps search for another solution. Thanks a bunch
I'm not sure how often the browser would refresh it in this case, but you can also use a php file as an image. Obviously you have the php file return the image header, but the rest is done through the GD library. Read the basics about it if you want to do it that way. The main function you'll need is: ImageCreateFromJPEG() (JPEG can be replaced with GIF, WBMP, or PNG).
the best way to do what i think you're trying to do is this: in your stylesheet, have style_1 {} style_2 {} style_3 {} and then in your backend code, have a random number generate a number 1, 2, or 3, and insert it into your class, like <div class="style_<? generate number here ?>> HTH Edelman
Thanks for your help. So we should have a lot of style_X {} with this solution, isn't it? Have a nice day
meh meh meh! Don't have your apache engine parse css files as .php, this is extremely wrong as another member already commented. You should use different styles and rotate the style type within the php file instead of parsing the css file. Hexed
Perhaps it's look like comment no 6? I'm still confusing... sorry... Thanks a bunch... Have a great day
Solved! Many thanks for your helps. Here my solution: - using "AUTOMATIC IMAGE ROTATOR" from http://www.automaticlabs.com/ - in the rotate.php file use this parameter $folder = 'images/' . $_GET['folder'] . '/'; Code (markup): - in CSS file use style_1 {background-image: url(rotate.php?folder=folder1)} style_2 {background-image: url(rotate.php?folder=folder2)} style_3 {background-image: url(rotate.php?folder=folder3)} Code (markup): - place my images into images/$folder. $folder should be folder1, folder2, and folder3 - bingo... Thanks for all of you guys. I use it for my adsenseBeautifier to make random images near adsense code. Any suggestion for a better solution? Thanks... Have a wonderfull day and gud lak