0

I want to include my css file in php can someone help me how to add ?

 include('config.php');
 $cssFile = "style.css";
 echo "<link rel='stylesheet' href='/books/style.css'>";

How to add my css in PHP application?

2
  • i have to files 1 php and 2 is css , i want to style some thing in php page so how i can? Commented Jun 6, 2018 at 11:09
  • What is the outcome your expect? What are you trying to accomplish? Commented Jun 6, 2018 at 11:17

3 Answers 3

1

Considering your PHP starts with <?php or <? tags, you can add the CSS to the top of your php file (or after some lines if you are sending headers though php) out of the php tags.

Dont forget that styling applies to HTML code, so it needs to be out of PHP. If your PHP produces html code, you can use normal CSS there too.

Example :

<html>
<head>
<link rel='stylesheet' href='/books/style.css' type="text/css">
</head>
<body>
<?php
include('config.php');
//your php code here
?>
</body>
</html>
Sign up to request clarification or add additional context in comments.

Comments

1

I use external css file during pdf generation and it works for me.

Try this.

$stylesheet = '<style>'.file_get_contents('path/style.css').'</style>';

Comments

0

Asked and answered already. Please make sure to search Google first. I found many tutorials and answers already out there :). I like this one the best: https://stackoverflow.com/a/6315792/1015712.

Full question and answer here: How to import/include a CSS file using PHP code and not HTML code?

It was 6 years ago, but I don't think newer PHP versions have change this.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.