It's simple:
<?php
include "css/style.css"; // include the 'style.css' file in a directory
?>
More detail: read-on
Using include
:
<?php
include "css/style.css"; // include the 'style.css' file in a directory named 'css'
include "style.css"; // include the 'style.css' file in current directory
include "../style.css"; // include the 'style.css' file in parent directory
?>
Using require
:
<?php
require "css/style.css"; // include and require the 'style.css' file in a directory named 'css'
require "style.css"; // include and require the 'style.css' file in current directory
require "../style.css"; // include and require the 'style.css' file in parent directory
?>
Note 1: What's the difference between include
and require
?
include
includes the file, and it throws an error when the file is not found.
require
includes and require the file, and it exit (stop reading) the file when the file is not found.
Note 2: How to use this script in HTML?
It would not be easy to use this script in an .html
file. But this does not means it's impossible. The simplest way to do this is to use .htaccess
file. You can create a file named .htaccess
and put the following content in there:
AddType application/x-httpd-php .html .htm
Note that this might not always work when your/your-hosting-company's computer or server does not support htaccess. And in my opinion, this is not a smart thing to do.
More Info:
http://php.net/manual/en/function.include.php
http://php.net/manual/en/function.require.php
Using .htaccess to make all .html pages to run as .php files?