开发者

Generating CSS from PHP

开发者 https://www.devze.com 2023-03-14 06:18 出处:网络
I\'ve read a lot a blogs and forums but I\'m still having trouble getting this to work. I allow my users to change their user account style sheet.

I've read a lot a blogs and forums but I'm still having trouble getting this to work. I allow my users to change their user account style sheet.

I've added the &开发者_StackOverflow中文版lt;?php header("Content-type: text/css"); ?> to the top of the style.php and I've included that file into my html.

But all I can see is

<style>
box {
color:#;
background-color:#;
</style>

The values aren't showing up. Any pointers?


I'm going to take a wild guess here since we can't see your stylesheet...

You aren't using echo for the values.

Either that, or as Rytmis said, the values are in fact empty.

No point in trying to set the content type header if you're using include to output the CSS in a <style> block, you should be referencing the file with a <link> tag.


There's nothing special to generating CSS as opposed to generating HTML, so if your values aren't showing up, chances are there are no values there. First, check your assumptions: see if you've got values in your data source. Then, if you do, try debugging to narrow down to the point where you no longer have them, and there's your problem.


the header, if you use one, must precede ANY content. you are better off writing the css directly into the page (my first suggestion) or maybe using a temporary file if you can find a way to write it to the server and access it on the browser.

otherwise, you have the problem of "how to I point my html document to a spontaneously generated css file with no content? there's no filepath!

unless of course you use something like #CDATA or #PCDATA I think and BASE64 encode your document and thus embed it inside style tags. I have seen this trick done with src attributes on img tags. no filename, just straight data feed. there are examples on the internet, but my browser has been zapping important entries from the bookmarks lately (firefox). good way to hide your source code, terrible for maintainability.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号