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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:35:10+00:00 2026-06-13T11:35:10+00:00

I am Looking for a PHP solution that would allow creating HTML in the

  • 0

I am Looking for a PHP solution that would allow creating HTML in the following style:

$head=new Head();
$title=new Title("The title of the page");
$head->setTitle($title);

$body=new Body();
$h1=new H(1,"Header 1");
$body->add($h1);

$html=new HTML();
$html->setHead($head);
$html->setBody($body);

echo $html->asHTMLString();

What PHP Libraries have a similar API?
I am not interested in “What is the best …?” just the fact that the API is comparable is what I’d like to know.

  • 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-13T11:35:11+00:00Added an answer on June 13, 2026 at 11:35 am

    I do have a none OO version at this time that looks like this:

    <?php
    /**
     * HTML Abstraction
     */
    
       // html
       function html($html) {
         return tag("html",$html,-1,0);
       } 
    
       // body
       function body($body,$indent=1) {
         return tag("body",$body,$indent,$indent);
       }
    
       // head
       function head($head,$indent=1) {
         return tag("head",$head,$indent,$indent);
       }
    
       // image
       function img($src,$alt,$width,$height,$indent=-1) {
         return attrtag("img",attr("src",$src).attr("alt",$alt).attr("width",$width).attr("height",$height),"",$indent,$indent);
       }
    
       // table
       function table($lt,$indent=3) {
         return tag("table",$lt,$indent,$indent);
       }
    
       // title
       function title($title,$indent=2) {
         return tag("title",$title,$indent,-1);
       }
    
    
    
       // tag with possible indentation
       function tag($tag,$ltagcontent,$openindent=-1,$closeindent=-1) {
          return attrtag($tag,"",$ltagcontent,$openindent,$closeindent);
       }
    
       function td($ltd,$indent=5) {
         return tag("td",$ltd,$indent,$indent);
       }
    
       function th($lth,$indent=5) {
         return tag("th",$lth,$indent,$indent);
       }
    
       function tr($ltr,$indent=4) {
         return tag("tr",$ltr,$indent,$indent);
       }
    
       function a($href,$la,$indent=-1) {
         return attrtag("a",attr("href",$href),$la,$indent,$indent);
       }
    
       function h($h,$lh,$indent=-1) {
         if ($indent<0) 
           $indent=$h+1;
         return tag("h".$h,$lh,$indent,-1);
       }
    
    
       // an attribute with a given value
       // or empty if value is not set
       function attr($attr,$value) {
         if (empty($value))
           return "";
         else
           return " ".$attr."='".$value."'";
       }
    
       // attributed tag, possibly indented
       function attrtag($tag,$attr,$ltagcontent,$openindent=-1,$closeindent=-1) {
        $html="<".$tag.$attr;
        if ($openindent>=0)
          $html="\n".indentation($openindent).$html;
        if (empty($ltagcontent)) {
          $html.="/>";
            if ($closeindent>=0)
              $html.="\n".indentation($closeindent);
        } else {
            $html.=">".$ltagcontent;
            if ($closeindent>=0) {
              $html.="\n".indentation($closeindent);
            }
            $html.="</".$tag.">";
        }
        return $html;
       }
    
       // indent the given lines
       function indent($html,$indent) {
         $result="";
         $lines=explode("\n",$html);
         foreach($lines as $line) {
           $result.=indentation($indent).$line."\n"; 
         }
         return $result;
       }
    
    
       // indentation by the given count
       function indentation($count) {
         return str_repeat("  ",$count);
       }
    
       // adds a newline    
       function line($line) {
         return $line."\n";
       }
    
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking for the following solution in PHP. Whenever a user clicks on a
I'm looking at PHP date() documentation and thought that 'I' would tell me whether
I'm looking for some tool that would do basic testing of PHP script. This
I'm looking for a solution/best practice for the following issue. I have a page
i am looking for a php logging solution like log4net. do you know any
I'm looking for a PHP script that can be run as a cron job
I'm looking for a PHP library that allows me to scrap webpages and takes
I am looking for a PHP IDE to work with that contains a design
I'm looking for a PHP-like high level C utility library. I've found the following
I need to create an acoustic warning in a PHP backed page that plays

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.