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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:33:05+00:00 2026-05-16T06:33:05+00:00

Anyone know of any classes written for php that can clean up your code

  • 0

Anyone know of any classes written for php that can clean up your code a bit?

Something like,

$htGen = new HTMLGenerator();
$htGen->newDOM('div', 'here is what goes in the div', 'optionalID', 'optionalClass');

Or does that just sound redundant?

I end up with some complex looking mish-mashes of html and php sometimes that I feel could be simplified a bit eg my latest cms bit;

foreach($details as $detail){

    $d = unserialize($detail);

    if($ad){
        print_r($d); // <-- VIEW DETAIL OBJECT IN WHOLE.
    }else{
    if($d->get_info('orphan')){
        echo '<li class="classRow orphan">' . "\n";
        echo '<div class="orphan" style="display:none">orphan</div>' . "\n";
    }else{
        echo '<li class="classRow">' . "\n";
        echo '<div class="orphan" style="display:none"></div>' . "\n";
    }

        echo '<div  class="classNumbers" id="' . $d->get_info('class ID') .  '" style="display:none"></div>' . "\n"; 
        echo '<div class="rowBG" style="overflow:hidden;width:100%">';   
            echo '<div class="startTime"></div>' . "\n";
            echo '<div class="details"><span class="classes">' . $d->get_info('class number') . '</span> - <input class="detailInput" type="text" value="' . $d->get_info('class description') . '"/><div class="editButton"><a class="editExpand">options(+)</a></div></div>' . "\n";
            echo '<div class="interval">';
            echo '<input class="intervalInput" type="text" value="' . $d->get_info('interval') . '" maxlength="5"/>';
            echo '</div>' . "\n"; 
            echo '<div class="numRiders"><input class="numRidersInput" type="text" value="' . $d->get_info('num riders') . '"/></div>' . "\n"; 
        echo '</div>'; 

        echo '<div class="classOptions">' . "\n";
            echo '<div class="selectRingMove">Move to Ring:<select id="ringSwap"><option>Select A Ring</option>' . get_ring_options() .  '</select></div>' . "\n";
            if($d->get_info('online sign up') != 'false'){
                echo '<div class="signUpContainer">Sign-Up<input type="checkbox" class="signUp" checked/></div>' . "\n";
            }else{
                echo '<div class="signUpContainer">Sign-Up<input type="checkbox" class="signUp"/></div>' . "\n";
            }
            if($d->get_info('water and drag')){
                echo '<div class="wdBoxContainer"><select id="wdDescrip"><option>WATER AND DRAG</option><option>COURSE CHANGE & WALK</option><option>OTHER</option></select><input type="checkbox" class="wdBox" checked/><input type="text" value="' . $d->get_info('water and drag') .  '" maxlength="2" class="wdInput"> min</div>' . "\n";
            }else{
                echo '<div class="wdBoxContainer"><select id="wdDescrip"><option>WATER AND DRAG</option><option>COURSE CHANGE & WALK</option><option>OTHER</option></select><input type="checkbox" class="wdBox"/><input type="text" value="20" maxlength="2" class="wdInput"> min</div>' . "\n";
            }
            if($d->get_info('ghost riders')){
                echo '<div class="ghostRidersContainer">Ghost Riders<input type="checkbox" checked class="ghostBox"><input type="text" maxlength="2" class="ghostRiderInput" value="' . $d->get_info('ghost riders') .  '"></div>' . "\n";
            }else{
                echo '<div class="ghostRidersContainer">Ghost Riders<input type="checkbox" class="ghostBox"><input type="text" maxlength="2" class="ghostRiderInput"></div>' . "\n";
            }

        echo '</div>' . "\n";

    echo '</li>' . "\n";

    if($d->get_info('water and drag')){
        echo '<li class="waterAndDragRow" style="display:block;"><span class="wdStartTime">08:33am</span> - <span class="wdEndTime">08:34am</span> <input type="text" class="wdDescription" value="' . $d->get_info('water and drag description') . '"></li>';
    }
    }
}

Or, if you know of a cleaner way to write long blocks of intermingled php vars and html… (not a big fan of EOF>>>)

Thanks in advance.

  • 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-16T06:33:05+00:00Added an answer on May 16, 2026 at 6:33 am

    I guess it could be done with http://www.php.net/manual/en/class.domdocument.php. But that isn’t really a good way to do it.

    I agree that your code code sample isn’t very clear, you could consider something like:

    <ul>
    <?php foreach ($items as $item): ?>
        <li>
            <?=$item['something']?>
            <?php if ($item['foo'] == 'bar'): ?>
            <ul>
                <li>bar</li>
            </ul>
            <?php else: ?>
            <ul>
                <li>foo</li>
            </ul>
            <?php endif; ?>
        </li>
    <?php endforeach; ?>
    <ul>
    

    That’s a lot better imho, I use it like that in my views.

    Btw, you should validate your html output. For example, a div-element isn’t allowed in a li-element.

    edit:
    Obviously, the following code:

    <?php if ($item['foo'] == 'bar'): ?>
    <ul>
        <li>bar</li>
    </ul>
    <?php else: ?>
    <ul>
        <li>foo</li>
    </ul>
    <?php endif; ?>
    

    Could be replaced by:

    <ul>
        <li><?=($item['foo'] == 'bar' ? 'bar' : 'foo')?></li>
    </ul>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone know any site or book that presents problems like python challenge ,
Does anyone know of any good XmlMembershipProvider and XmlRoleProvider classes that are able to
Does anyone know of any utilities / plugins that can be used to extract
does anyone know any sort of app that lets users visit a page on
Possible Duplicate: PHP: Script for generating Crossword game? Does anyone know any PHP-based simple
Does anyone know of any resources or books I can read to help me
Hi does anyone know if there are any inbuilt classes for resolving a bound
Does anyone know of any tweaked version of POCO T4 template that generates interfaces
So I have some code that looks like this, written in and compiled with
Does anyone know if OO and php classes are more resource consuming than normal

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.