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).

    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题