To include a css file to .php file.

Inside the .php file, We have;

Php Code
<?php
Loads of code..
?>
[ad type=”banner”]

We want it like this..

Php Code
<?php
<link href="bootstrap/css/bootstrap-responsive.css" rel="stylesheet">
Loads of code..
?>

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 :

Php Code
<?php
echo '<link href="bootstrap/css/bootstrap-responsive.css" rel="stylesheet">';
?>

Use include/require :

Php Code
<style><? include_once ”PATH/your_style.css" media =""  ?></style>
//
<style><? require_once ”PATH/your_style.css" media ="" ?></style>
[ad type=”banner”]

same as you normally do in a HTML file.

Php Code
<?
<head>
<link href=”PATH/your_style.css” >
</head>
?>

Consider your CSS file as a PHP file.

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

Php Code
<?
header("Content-type: text/css; charset: UTF-8");

$style_tipo = "Helvatica, Arial, sans-serif";
$style_colour= rgba(255, 255, 255, 30);
....

a { color: <? echo tyle_colour ?> }
....
?>

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.

Php Code
<link rel="stylesheet" href="main.css" type="text/css">

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.

Php Code
<?php include 'header.php'; ?><style><?php include 'CSS/main.css'; ?></style>
[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:

php Code
<link rel="stylesheet" type="text/css" href="my-style.css">

Php Code
<?php

echo '<head>';
echo ' <link rel="stylesheet" href="/styles.css" type="text/css">';
echo '</head>';

require( "config.php" );

$Quote = new CQuote;

if( $Quote->Get( $strQuote ) == 0 )
echo $strQuote;

?>
[ad type=”banner”]

Categorized in: