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

  • Home
  • SEARCH
  • 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 8937655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:27:05+00:00 2026-06-15T10:27:05+00:00

In my PHP scripts, I concatenate a lot HTML mixed with some PHP/MySQL data

  • 0

In my PHP scripts, I concatenate a lot HTML mixed with some PHP/MySQL data (the first example). Typically, my code looks like a mess because you can’t bring any structure into this mix of code.

So, I was wondering, is the second script slower (or less performance) then the first script?

First script

$message = <div class="label" style="width:200px; float:left; text-align:right;">Organisation:</div>   
<div class="input" style="margin-left: 210px;"><b>' . $item1[0]['organisation'] . '</b>
</div><div class="label" style="width:200px; float:left; text-align:right;">Group:</div> <div class="input" style="margin-left: 210px;"><b>' .
  $item1[0]['group'] . '</b></div><div class="label" style="width:200px; float:left; 
text-align:right;">Name:</div> <div class="input" style="margin-left: 210px;"><b>' . $item1[0]['firstname'] . ' ' . $item[0]['lastname'] . '</b></div>

Second script

$message  = <div class="label" style="width:200px; float:left; text-align:right;">Organisation:</div>   
$message .= <div class="input" style="margin-left: 210px;"><b>' . $item1[0]['organisation'] . '</b></div>
$message .= <div class="label" style="width:200px; float:left; text-align:right;">Group:</div> 
$message .= <div class="input" style="margin-left: 210px;"><b>' .$item1[0]['group'] . '</b></div>
$message .= <div class="label" style="width:200px; float:left; text-align:right;">Name:</div> 
$message .= <div class="input" style="margin-left: 210px;"><b>' . $item1[0]['firstname'] . ' ' . $item[0]['lastname'] . '</b></div>

Or are there even better ways to handl PHP generated HTML pages?

  • 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-15T10:27:06+00:00Added an answer on June 15, 2026 at 10:27 am

    Readability should always take priority over performance optimization. The fact that you’re asking which one is faster is an indication that you have not actually traced any performance detriments back to the code in question. What you really seem to be asking is how to make the code more readable, which is understandable since code is meant to be read by humans and executed by computers.

    My first advice in these situations is to always exit the PHP parser when you are outputting a large chunk of HTML and only tiny portions of PHP code.

    <?php
    /* Put your PHP code here */
    $PHP = "PHP";
    ?>
    <p>This is some html with a little <?php echo $PHP ?> code</p>
    

    By closing your PHP tags to write large chunks of HTML code you simply tell PHP to stop parsing PHP code and output everything that follows as plain text up until another opening PHP tag is found.

    Another option is to use heredoc syntax which doesn’t require all the messy single/double quote escaping.

    Variable interpolation is possible directly inside string syntax so the following works:

    $string = <<<EOL
    <p>This is some html with a little $PHP code</p>
    EOL;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Are PHP scripts reads from top to bottom? like HTML? because in this code
I have numerous index.php scripts using SEO-friendly arg format like example.com/path/to/index.php/opt/arg and would like
I'm trying to make a search in a table, something like this: http://www.phpjabbers.com/free-scripts/mysql-search-table/search.php I
I saw some existing code in the PHP scripts doing a system('hostname'); how big
I am forking some php scripts and I need to update a mysql row
my php scripts usually send mail with users data to a mailbox on my
I have php scripts that do things like register, login, upload. I would like
Im using MySQL with PDO PHP scripts to maintain a user database and a
I have some php scripts that handle uploaded files via forms and stores them
I have some PHP scripts that are accessed by external non human sources. Normally

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.