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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T08:47:11+00:00 2026-06-06T08:47:11+00:00

I am fairly new to php and was wondering how I would go about

  • 0

I am fairly new to php and was wondering how I would go about improving this code. I know its not perfect but any constructive criticism is encouraged as I am trying to better myself in PHP. Please all I ask is that if you do answer with a way to improve it you expand upon the answer a little and let me know why it is better so I can get the full over view of the improvement.

public function displayArticle(){
    //Check to see if we are getting the home page
    if($_GET['page'] == 'home'){
        //Display the results formatted
        $content = "<article class=\"igpPost\">";
            $content .= "<div class=\"igpPost-Divider\"></div>";
            $content .= "<header>";
            $content .= "<h3><a href=\"#\">Ready Up – StarCraft 2, LoL, and Dota 2 pros head to DreamHack Summer</a></h3>";
            $content .= "<div class=\"igpPost-AuthTime\"><span>Posted By: </span><a href=\"#\">Cameron Lockhart</a> <span>at 07:44PM on June 15, 2012</span></div>";
            $content .= "<div class=\"igpPost-AuthTime\"><span>Tags: </span><a href=\"#\">TAG HERE</a> ,<a href=\"#\">TAG HERE</a> ,<a href=\"#\">TAG HERE</a> ,<a href=\"#\">TAG HERE</a> ,<a href=\"#\">TAG HERE</a> ,<a href=\"#\">TAG HERE</a></div>";
            $content .= "<div class=\"igpPost-Img\"><img src=\"images/news/DreamHack-Summer-2012-logo.jpg\"/></div>";
            $content .= "</header>";
            $content .= "<p>Did last week’s MLG Spring Championship leave you thirsting for more eSports? Then DreamHack Summer 2012 has you covered. With well-attended tournaments for StarCraft 2, League of Legends, and Dota 2, DreamHack should keep you busy throughout the weekend and into the work-week. It starts tomorrow at 11 AM Eastern, and continues through Monday, with the StarCraft 2 Grand Final scheduled for 5:15 PM Eastern.</p>";
            $content .= "<footer class=\"igpPost-Footer\">";
            $content .= "<div class=\"igpPost-ReadMore\">";
            $content .= "<h1><a href=\"#\">Read More..</a></h1>";
            $content .= " </div>";
            $content .= "</footer>";
            $content .= "</article>";
    }
        //If it is not the home page and it is a single article
        if($_GET['article']){
            //Display the article formatted
        }
}

Also this is obviously not a completed script but looking at it it looks like to much for PHP. I read some tutorials and I think they sent me in the wrong direction with being correct and using good PHP.

Update: I went through and tried to revise some of the code so that it gave a more descriptive overview:

$sql = "SELECT * FROM articles LIMIT $number";
        $stmt = $pdo->query($sql);
        $stmt->setFetchMode(PDO::FETCH_ASSOC);

        while($row = $stmt->fetch()){
            //Display the results formatted
            $content = "<article class=\"igpPost\">";
            $content .= "<div class=\"igpPost-Divider\"></div>";
            $content .= "<header>";
            $content .= "<h3><a href=\"index.php?article=" . $row['id'] ."\">" . $row['title'] . "</h3>";
            $content .= "<div class=\"igpPost-AuthTime\"><span>Posted By: </span><a href=\"#\">" . $row['author'] . "</a> <span>at " . formatDateTime($row['datetime']) . "</span></div>";
            $content .= "<div class=\"igpPost-AuthTime\"><span>Tags: </span>";
            $content .= "<div class=\"igpPost-Img\"><img src=\"" . $row['imglocation'] ."\"/></div>";
            $content .= "</header>";
            $content .= "<p>" . $row['content'] . "</p>";
            $content .= "<footer class=\"igpPost-Footer\">";
            $content .= "<div class=\"igpPost-ReadMore\">";
            $content .= "<h1><a href=\"index.php?article=" . $row['id'] ."\">Read More..</a></h1>";
            $content .= " </div>";
            $content .= "</footer>";
            $content .= "</article>";

            echo $content;
        }

This is what im going for, im basically trying to separate the html from the PHP but insert the dynamic content in the places it needs to be. This is all within a class.

  • 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-06T08:47:13+00:00Added an answer on June 6, 2026 at 8:47 am

    You can use a variety of things here, including heredoc syntax (the direct equivalent of what you have):

                $content = <<<END
    <article class="igpPost">
        <!-- ... -->
    </article>
    END;
    

    (Note that you can’t indent the END; part.)

    Another option is to use output buffering and include a content script:

    ob_start();
    include 'someViewFile.php';
    $content = ob_get_contents();
    ob_end_clean();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm fairly new to PHP so am not sure how to do this. I
I am fairly new to php and have not figured out how I would
I've fairly new to PHP MVC and I'm not 100% sold I'm doing this
I am fairly new to OOP but not new to PHP. I am trying
I'm fairly new to php and was wondering how do I validate the array
I am fairly new to php and mysql but I have created a small
I'm fairly new to PHP and MongoDB so it would be really helpful if
So i am fairly new to PHP (worked with it a little, not much
I am fairly new to PHP and Codeigniter so im sure this will be
I am fairly new to PHP, but have applied my previous knowledge of programming,

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.