Nick Manning Nick Manning - 1 year ago 83
PHP Question

Can I use file_get_contents to load css?

Instead of this:

<link rel="stylesheet" type="text/css" href="css_file.css" />

I want to do this:

<style><?php file_get_contents("css_file.css");?></style>

For some reason though, the text shows up in the doc but the style is not applied. This is a two part question:

  1. Why is this not working?

  2. Is this a bad idea to do this?

Answer Source

This question was posted when I was a beginning developer. I didn't know about Sass and other easier and better ways to achieve variables in CSS. I also didn't know about browser caching.

Jeremy Karlsson answered the question in a comment. file_get_contents requires echo.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download