-3

I created a website using php, html, and css.

I used <link rel="stylesheet" src="main.css"> to call css file to the html document, but when i using php to write/echo/print the "<link rel="stylesheet" src="main.css">" the css is not loaded even not detected on the consoles.

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title><?php $this->actn->getAction("pageTitle"); ?></title>
        <?php 
        if(isset($preq[0]) && $preq[0] != "report" && $preq != "action") {
            switch($preq[0]) {
                default:
                    echo "<link rel=\"stylesheet\" src=\"".$purl."source/lib/css/main.css\"> \n";
                    echo "<link rel=\"stylesheet\" src=\"".$purl."source/lib/css/functional.css\"> \n";
                    echo "<link rel=\"stylesheet\" src=\"".$purl."source/lib/css/header.css\"> \n"; break;
            }
        } else {
            return null;
        } ?>
    </head>
    <body>
        <div class="container">
            <?php $this->sect->getSection(); ?>
        </div>
    </body>
</html>

the console that doesn't show anything

note: I'm using php 7.0.13

Mehravish Temkar
  • 4,275
  • 3
  • 25
  • 44

2 Answers2

1

have a look at Difference between SRC and HREF you need the href attribute instead of src, so change your code to:

   echo "<link rel=\"stylesheet\" href=\"".$purl."source/lib/css/main.css\"> \n";
   echo "<link rel=\"stylesheet\" href=\"".$purl."source/lib/css/functional.css\"> \n";
   echo "<link rel=\"stylesheet\" href=\"".$purl."source/lib/css/header.css\"> \n";
FatFreddy
  • 1,160
  • 1
  • 9
  • 16
0

Use ' instead of " for your echos it will be easier and will prevent some problems.

echo '<link rel="stylesheet" src="'.$purl.'source/lib/css/main.css"> \n';
echo '<link rel="stylesheet" src="'.$purl.'source/lib/css/functional.css"> \n';
echo '<link rel="stylesheet" src="'.$purl.'source/lib/css/header.css"> \n';
Firefly
  • 214
  • 1
  • 11
  • 1
    this might interest you, with " you can put $vars directly in it or {$this->var} objects, or {$var['elem']} arrays without having to use the ". $var ." method. i.e. echo "{$this->text}"; – Andrew Killen May 09 '18 at 07:05