0

I have a lot of css/javascript file that I'm using on mutiple pages. So I included them in my php file.

styles.php :

<?php
# SCRIPTS/CSS BEGIN | DEBUT DES SCRIPTS/CSS
include'css/base.css';
include'/css/style.css';
include'/css/base2.css';
include'/css/style-menu.css';
# SCRIPTS/CSS ENDS | FIN DES SCRIPTS/CSS


# SCRIPTS/JS BEGIN | DEBUT DES SCRIPTS/JS
include'/js/base.js';
include'/js/menu.js';
# SCRIPTS/JS ENDS | FIN DES SCRIPTS/JS
?>

Now, on my html pages I'm trying to include the styles.php file. However I'm not able to do it.

My file is located to this path: /opt/lampp/htdocs/src/php/styles.php

This is the path of the html file: /opt/lampp/htdocs/src/html/index.html

I tried to use the followings code but none of them succeed:

<?php include '/src/php/styles.php'; ?>

<?php include '/php/styles.php'; ?>

<?php include './php/styles.php'; ?>

I get the following error.

Warning: include(./php/pi-ip-en.php): failed to open stream: No such file or directory in /opt/lampp/htdocs/src/html/index.html on line 29

Please let me know what's wrong. It looks like it ignores my path, thanks.

1 Answer 1

1

You can't include files in html with php. You need to insert a link or script tag with the specific href or src attribute using php.

...
echo '<link rel="stylesheet" href="' . $yourUrlHere . '">';
...
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.