douzi8916 2014-02-23 21:39
浏览 53

包括css url中的php代码

Hi I need to include a php code to a folder in one of my css file. This is how I have link my images and other things together and it works.

For example for image I normally do this:

<img src="<?php $directories->fetchdir($img); ?> MYIMAGE.png" /> 

This will general turn out to be www.example.com/html/img/MYIMAGE.png

directories <--- this is my class
fetchdir <-- this is my function 

I have try the same thing in my .css file and its not working. I have try the same method in my test.css file. below is what I have try

@font-face {
    font-family:'FontAwesome';
    src:url('<?php $directories->fetchdir($fonts);?>fontawesome-webfont.eot?v=4.0.3');
}

Please help. Thanks!

  • 写回答

2条回答 默认 最新

  • doumanshan6314 2014-02-23 21:43
    关注

    The answer will depend on the server your running. Are you using Apache? (Chances are that you are.)

    The issue is that Apache doesn't know that you want to process CSS files as PHP. You can add this line to your .htaccess file make it.

    AddType application/x-httpd-php .css
    

    Note: This is probably not a good idea. The more script you process, the more time it'll take to serve your user their content and the more chances there are for security holes. As mentioned above, you can simply include CSS code in the head of your document with <style> tags (the PHP will process properly there).

    评论

报告相同问题?

悬赏问题

  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容