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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:49:25+00:00 2026-05-13T12:49:25+00:00

I’ve been working with php for about a year now and am finally starting

  • 0

I’ve been working with php for about a year now and am finally starting to make some headway in my understanding of OOP. So, now that I’m writing classes I’m looking for the cleanest methods of working my PHP into my HTML. I essentially have written a few classes that output data stored in my database.

For instance I’ll instantiate an instance of a “user” class for which I’d written a function called getUserNameByIndex($index) which “echos” a value that I can then write into my HTML in my preferred manor like:

<h1> The <?php $user->getUserNameByIndex($index) ?> is not online </h1>

That’s great. What’s bumming me out is if I have an array of strings I need returned I then need to write more PHP into my HTML, making my output page look more like another PHP script.

For instance:

<span> His likes are:<br> <?php foreach($user->likes as $like){ if($like != foo){echo $like . '<br>' }} ?>

It just doesn’t seem as clean to me, but if I write the output into the class method, I’m taking away some of my style control. I’m wondering if there is a balance here I should be looking for. Or if there is a standard method for handling arrays of strings that you intend to display in your HTML. I hope this makes sense and is not a dumb question. I’m so thrilled to be writing HTML that looks like HTML again, that anyway to minimize the PHP footprint in my code is a big bonus.

Thanks for your consideration.

  • 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-13T12:49:26+00:00Added an answer on May 13, 2026 at 12:49 pm

    A good way to separate code from design is the Model-View-Controller (MVC) design pattern.
    Specifically, in your case you are looking for a separation of model (data handling) and view (display).

    There are many implimentations of it already in existence in PHP. A few that are worth looking at are:

    CodeIgniter
    Kohona
    Symfony
    Zend

    (And, if you are not against using a templating language as a templating language parser, may I suggest looking at Tiny But Strong.)

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

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

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.