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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:27:50+00:00 2026-06-08T18:27:50+00:00

Very simple question, requiring a very simple answer. If I’ve got some PHP files

  • 0

Very simple question, requiring a very simple answer.

If I’ve got some PHP files that need to output a decent amount of html with variables, is it considering better to use echo/printf or is it better to end the php and start it up again?

ex:

<?php
$varA = 'foo';
$varB = 'bar';
?>
<span><?php echo $foo; ?></span>
<div><?php echo 'content ' . $bar; ?></div>
<?php
//continue php here
?>

is that considered better than

<?php
$varA = 'foo';
$varB = 'bar';
printf('<span> . $foo . </span>');
printf('<div>content ' . $bar . '</div>');
//continue php here
?>

or is the latter considered “better”, OR is one even considered better than the other, period!?

Thanks!

  • 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-06-08T18:27:51+00:00Added an answer on June 8, 2026 at 6:27 pm

    The answer here is fairly subjective, so my opinion is that the first approach is cleaner and easier to read, due mainly to the fact that if you happen to be working with a team who’s attempting to exercise some separation of concerns, then the front-end developer will have an easier time spotting the HTML tags if they themselves are not echo‘d out by PHP (They may not even know PHP). Most text editors will not provide the pretty syntax highlighting for the HTML if it is wrapped in a PHP string.

    It might also be noted that if you are working in a strict MVC environment, then your views should contain as little PHP as possible, and should really just be a bunch of echos. I think the first approach lends itself towards providing a more HTML look and feel, if you will.

    As @hyphen-this has stated, heredoc syntax is also an accepted route, and removes the need for jumping in and out of PHP mode.

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

Sidebar

Related Questions

very simple question here but I don't have the answer... ;-) I just need
Very simple question. I need to perform a task when the user closes his
A very simple question I can't seem to find a definitive answer for. I
I've got a very simple question around Rails MVC/application design with a focus on
Seems like a very simple question here: I've got a program where someone is
Very simple question, is it possible to make a variable that is retrieved from
very simple question (but I can't find the answer on the Web...): I have
A very simple question, which a found no answer to. How do I print
Very simple question... I'm having an issue that an if statement isn't working? All
Very simple question. How do i get this string: $endDate = 01/14/2088 Some code

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.