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 219357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:50:14+00:00 2026-05-11T18:50:14+00:00

So I have seen some comments on various web sites, pages, and questions I

  • 0

So I have seen some comments on various web sites, pages, and questions I have asked about separating php and html.

I assume this means doing this:

<?php

myPhpStuff();

?>

<html>

<?php

morePhpStuff();

?>

Rather than:

<?php

    doPhpStuff();

    echo '<html>';

    ?>

But why does this matter? Is it really important to do or is it a preference?


Also it seems like when I started using PHP doing something like breaking out of PHP in a while loop would cause errors. Perhaps this is not true anymore or never was.


I made a small example with this concept but to me it seems so messy:

<?php

$cookies = 100;
while($cookies > 0)
{
    $cookies = $cookies -1;
?>
    <b>Fatty has </b><?php echo $cookies; ?> <b>cookies left.</b><br>

<?php

} 

?>

Are there instances when it is just better to have the HTML inside the PHP?

<?php

$cookies = 100;
while($cookies > 0)
{
    $cookies = $cookies -1;

    echo'<b>Fatty has </b> '.$cookies.' <b>cookies left.</b><br>';
} 

?>
  • 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-11T18:50:14+00:00Added an answer on May 11, 2026 at 6:50 pm

    Let’s make it clear what is not separation

    • you switch from php mode to html mode
    • you use print or echo statements to write out html code
    • you use small php snipplets inside html files

    If you do this, there is no separation at all, no matter if you escape from php to html blocks or do it the other way and put php code into html.

    Have a look at a good templating engine, there are a plenty of reasons in the “why use ….” parts of the manuals. I’d suggert http://www.smarty.net especially http://www.smarty.net/whyuse.php

    It will answer all your questions now you have.

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

Sidebar

Related Questions

Have seen some similar questions: What is the difference between a JavaBean and a
I have seen some related questions but none focusing on the specific problem I
I have seen some mails which has HTML content embedded in them. The content
I have seen some demos about the jQuery wizard plugin on websites. But all
I have seen some bash/shell comments use the notation # Some comment block that
I was looking at some code and have seen these comments, how does promoting
I'm confused by some comments I've seen about blocking and cudaMemcpy. It is my
I have seen a few questions about this but I am unable to derive
I have seen some people in SO commenting that Singleton Pattern is an anti-pattern.
I have seen some instances where people will say you have to use JS

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.