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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T13:38:12+00:00 2026-06-06T13:38:12+00:00

I am studying PHP from a book. The author uses echo to output HTML.

  • 0

I am studying PHP from a book. The author uses echo to output HTML. At first I thought that this was how it supposed to be done, but then I picked up a more “advanced” book. The author of the second book inserted PHP code between HTML rather then echo the whole thing. How is it done in large web development companies that work on large projects? Can you use either, or is one more accepted than the other?

Take this code for example:

<?php
//pagination
if ($pages > 1) {
    //determine the current page
    $current_page = ($start / $display) + 1;

    //print out Previous Page button
    if ($current_page != 1) {
?>
        <div class="pages"><strong><a href="view_users.php?s=<?php echo ($start - $display); ?>&amp;p=<?php echo $pages; ?>">&nbsp;&lt;&nbsp;</a></strong></div>
<?php
    }

    //print the page numbers
    for ($i = 1; $i <= $pages; $i++) {
        if ($i == $current_page) {
?>
         <div class="pages active"><span>&nbsp;<?php echo $i; ?>&nbsp;</span></div>
<?php
    }
    else {
?>
        <div class="pages"><strong><a href="view_users.php?s=<?php echo ($display * ($i - 1)); ?>&amp;p=<?php echo $pages; ?>">&nbsp;<?php echo $i; ?>&nbsp;</a></strong></div>
<?php
        }//end of $i = $current_page conditional
    }//end of FOR loop

    if ($current_page < $pages) {
?>
        <div class="pages"><strong><a href="view_users.php?s=<?php echo ($start + $display); ?>&amp;p=<?php echo $pages; ?>">&nbsp;&gt;&nbsp;</a></strong></div>
<?php
    }
}//end of pagination

include('includes/footer.php'); 
?>

Is that the correct way of doing it, or should I use something like this:

echo '<a href="view_users.php?s=' . ($display * ($i - 1)) . 
'&p=' . $pages . '&sort=' . $sort . '">' . $i . '</a> ';

The reason why I’m asking is because I find it difficult to properly align the HTML when using the second technique, and I don’t want to develop any bad habits early on.

  • 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-06T13:38:14+00:00Added an answer on June 6, 2026 at 1:38 pm

    The first method makes your code more readable. The second method is useful when you need to print some little amount of html code. Also you can use short open tags to insert your php code between html tags. For example if you need to print language parameter of URL you can do like this:

    <a href="index.php?lang=<?=$lang?>" >A Link</a>
    

    This is equal to this:

    <a href="index.php?lang=<?php echo $lang; ?>" >A Link</a>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm studying this code: http://www.w3style.co.uk/a-lightweight-and-flexible-front-controller-for-php-5 In it the author uses a static function to
I just saw this code while studying the wordpress source code (PHP), You can
I've been started studying PHP in my spare time, and the first code example
I'm studying php programming and I'm pretty convinced I know base rules that permit
I am studying PHP,OOP and i am at Static, At this php.net/static i didnt
I am studying up on PHP and DDD. It seems to me that the
I was studying Ray Tracing on http://www.devmaster.net/articles/raytracing_series/part1.php when I came across this piece of
I am new to studying jquery.ajax. I want to paste some data from a.php
I am studying for the PHP 5 Certification exam. This function was mentioned in
I am studying OOP and this is my first study project. I created a

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.