Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3354532
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T02:17:04+00:00 2026-05-18T02:17:04+00:00

I have been designing websites for a while now, but there is one thing

  • 0

I have been designing websites for a while now, but there is one thing that I have never been quite sure of when using PHP and HTML. Is it better to have the whole document in PHP and echo HTML like so:

<?php
  doSomething();
  echo "<div id=\"some_div\">Content</div>";
?>

Or have a HTML file like so and just add in the PHP:

<html>
<body>
  <?php doSomething(); ?>
  <div id="some_div">Content</div>
</body>
</html>

It seems tidier to echo HTML, especially if lots of PHP gets used throughout the page, but doing so loses all formatting of the HTML i.e. colors in the IDE etc.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T02:17:04+00:00Added an answer on May 18, 2026 at 2:17 am

    There are varying opinions on this. I think there are two good ways:

    • Use a templating engine like Smarty that completely separates code and presentation.

    • Use your second example, but when mixing PHP into HTML, only output variables. Do all the code logic in one block before outputting anything, or a separate file. Like so:

      <?php $content = doSomething();
         // complex calculations
      ?>
      <html>
      <body>
        <?php echo $content; ?>       
        <div id="some_div">Content</div>
      </body>
      </html>
      

    Most full-fledged application frameworks bring their own styles of doing this; in that case, it’s usually best to follow the style provided.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have been using CruiseControl for quite a while with NUnit and NAnt. For
I have been working on designing a file server that could take the load
I have been developing websites for quite some time and I am not so
I have been tasked with designing an ecommerce solution. The aspect that is causing
I'm new to Qt and have been designing forms using Qt Creator. I've noticed
I've been designing and developing websites for a number of years now, however, whenever
I have been designing a program using Visual C# and have came across an
For past 7 months I have been designing web applications using open source technologies
I am new comer to android but not to java. I have been designing
I have been using SQL Server 2008 for about a year now and my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.