0

I am trying to write a PHP function, inside it, I am writing HTML code.

The problem is I am unable to link CSS file to the HTML code.

function foo() {
    // ---do some php stuff---
    echo '
    <html>
        <head>
           <link href="bar.css" type="text/css" rel="stylesheet"/>
        </head>
        <body
             ---some code---
        </body>
    </html>';
}

What should be the correct approach?

5
  • 1
    The correct approach would be, not to put your HTML in functions. Commented Jul 27, 2018 at 16:33
  • Are you sure, that path to css file is correct? Commented Jul 27, 2018 at 16:33
  • @LawrenceCherone how should I achieve what I am trying to do. Commented Jul 27, 2018 at 16:34
  • @Stranger yes the path is correct Commented Jul 27, 2018 at 16:34
  • what is the source HTML output that you get when you run this? Commented Jul 27, 2018 at 17:05

2 Answers 2

1
function foo() {
// ---do some php stuff---

$link_address = 'correct-path-for-css-file-from-root-folder/bar.css';

echo '
<html>
    <head>
       <link href="' . $link_address . '" type="text/css" rel="stylesheet"/>
    </head>
    <body
         ---some code---
    </body>
</html>';

}

I think this is working.try this.

Sign up to request clarification or add additional context in comments.

2 Comments

Now I have landed into one more problem, I want to use php tags again inside HTML. something like this <li><input type="text" placeholder="<?php echo $fz_variable?>"></li> How do I achieve that?
Here I have added answer for your other question.Try it. <?php echo '<li><input type="text" placeholder="';?> <?php echo '$fz_variable';?> <?php echo '?>"></li>';?>
0

Something like this should work

<style>
 .classname {
 padding: etc;
 margin: etc;
 }
</style>

echo "<div class='classname'>text here</div>";

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.