1

I am having trouble embedding my php inside my html. Im using the Bootstrap SB Admin template.

Here is my php, which is inside the <body>

<?php 
    $msg='<p>yo you yo</p>';
    echo $msg;
?>

No matter which method I try to insert my php, the page displays it incorrectly with my trailing ?> and other items displayed to the webpage

enter image description here

other methods include using <?...?> as well as placing the php in other sections of the html page.

The only other reason I can think that this would not be working would be if the template is causing the issue.

3
  • add the full code. Commented Jun 26, 2019 at 15:22
  • 4
    You cannot add PHP code to a HTML file and expect it to work, it wont. You can, however, add HTML to a PHP file and it will all work fine. Commented Jun 26, 2019 at 15:23
  • 2
    The reason you are seeing it "attempt to process" PHP is because XML tags are denoted with the <? beginning tag. Your files need to have a .php file extension and be (pre-)processed into HTML by PHP, either over CLI or (as typically done) over a webserver. PHP 7+ supports the -s option which allows you to run a PHP web server, self-contained in PHP. Read more here: (PHP Server inside PHP)[php.net/manual/en/features.commandline.webserver.php] Commented Jun 26, 2019 at 15:26

1 Answer 1

4

Your file needs to have .php as file extension, not .html. Otherwise PHP won't be parsed/processed.

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

1 Comment

oof thank you. I had been attempting using the .php file extension. I was confused why it was only displaying the script but that was because it wasnt opened on my local server. Again, thank you

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.