To include a css file to .php file.

Inside the .php file, We have;

[pastacode lang=”php” manual=”%3C%3Fphp%0A%09Loads%20of%20code..%0A%09%3F%3E” message=”Php Code” highlight=”” provider=”manual”/] [ad type=”banner”]

We want it like this..

[pastacode lang=”php” manual=”%3C%3Fphp%0A%09%3Clink%20href%3D%22bootstrap%2Fcss%2Fbootstrap-responsive.css%22%20rel%3D%22stylesheet%22%3E%0A%09Loads%20of%20code..%0A%09%3F%3E%0A” message=”Php Code” highlight=”” provider=”manual”/]

But obviously that doesn’t work. Is there any way to do this?

There are Four ways to solve this :

Solution 1 : echo a snippet.

Solution 1 : include/require

Solution 2: same as you normally do in a HTML file.

Solution 3:Consider your CSS file as a PHP file.

PHP is a server-side language,CSS is client-side and is used by the browser.

use echo :

[pastacode lang=”php” manual=”%3C%3Fphp%0A%09echo%20’%3Clink%20href%3D%22bootstrap%2Fcss%2Fbootstrap-responsive.css%22%20rel%3D%22stylesheet%22%3E’%3B%0A%09%3F%3E” message=”Php Code” highlight=”” provider=”manual”/]

Use include/require :

[pastacode lang=”php” manual=”%3Cstyle%3E%3C%3F%20include_once%20%E2%80%9DPATH%2Fyour_style.css%22%20media%20%3D%22%22%20%20%3F%3E%3C%2Fstyle%3E%0A%2F%2F%0A%3Cstyle%3E%3C%3F%20require_once%20%E2%80%9DPATH%2Fyour_style.css%22%20media%20%3D%22%22%20%3F%3E%3C%2Fstyle%3E%0A” message=”Php Code” highlight=”” provider=”manual”/] [ad type=”banner”]

same as you normally do in a HTML file.

[pastacode lang=”php” manual=”%3C%3F%0A%3Chead%3E%0A%3Clink%20href%3D%E2%80%9DPATH%2Fyour_style.css%E2%80%9D%20%3E%0A%3C%2Fhead%3E%0A%3F%3E%0A” message=”Php Code” highlight=”” provider=”manual”/]

Consider your CSS file as a PHP file.

( instead of your_style.css, work with your_style.php )

[pastacode lang=”php” manual=”%3C%3F%0A%20header(%22Content-type%3A%20text%2Fcss%3B%20charset%3A%20UTF-8%22)%3B%0A%20%0A%24style_tipo%20%3D%20%22Helvatica%2C%20Arial%2C%20sans-serif%22%3B%0A%24style_colour%3D%20rgba(255%2C%20255%2C%20255%2C%2030)%3B%0A….%0A%20%0Aa%20%7B%20color%3A%20%3C%3F%20echo%20tyle_colour%20%3F%3E%20%7D%0A….%0A%3F%3E%0A” message=”Php Code” highlight=”” provider=”manual”/]

Css file linking can be categorized in two ways :

 

By Html Code :

This is the traditional method for including CSS in your document.
It can be done by using link tag in head section of the document.

[pastacode lang=”php” manual=”%3Clink%20rel%3D%22stylesheet%22%20href%3D%22main.css%22%20type%3D%22text%2Fcss%22%3E%0A” message=”Php Code” highlight=”” provider=”manual”/]

By Php Code :

This is by far new and powerful way to import css in a document.

But the only condition is you have to surround the php code with style element.

[pastacode lang=”php” manual=”%3C%3Fphp%20include%20’header.php’%3B%20%3F%3E%3Cstyle%3E%3C%3Fphp%20include%20’CSS%2Fmain.css’%3B%20%3F%3E%3C%2Fstyle%3E%0A” message=”Php Code” highlight=”” provider=”manual”/] [ad type=”banner”]

CSS files aren’t linked to PHP, they are linked to HTML.

PHP can generate a line of HTML that references a CSS file like this:

[pastacode lang=”php” manual=”%3Clink%20rel%3D%22stylesheet%22%20type%3D%22text%2Fcss%22%20href%3D%22my-style.css%22%3E%0A” message=”php Code” highlight=”” provider=”manual”/]

[pastacode lang=”php” manual=”%3C%3Fphp%0A%0Aecho%20’%3Chead%3E’%3B%0A%20%20%20%20echo%20’%20%3Clink%20rel%3D%22stylesheet%22%20href%3D%22%2Fstyles.css%22%20type%3D%22text%2Fcss%22%3E’%3B%0Aecho%20’%3C%2Fhead%3E’%3B%0A%0Arequire(%20%22config.php%22%20)%3B%0A%0A%24Quote%20%3D%20new%20CQuote%3B%20%0A%0Aif(%20%24Quote-%3EGet(%20%24strQuote%20)%20%3D%3D%200%20)%0A%09echo%20%24strQuote%3B%0A%0A%3F%3E%0A” message=”Php Code” highlight=”” provider=”manual”/] [ad type=”banner”]

Categorized in: