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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T19:30:10+00:00 2026-05-29T19:30:10+00:00

Is there an standard output library that knows that php outputs to html? For

  • 0

Is there an standard output library that “knows” that php outputs to html?

For instance:

  1. var_dump – this should be wrapped in <pre> or maybe in a table if the variable is an array
  2. a version of echo that adds a "<br/>\n" in the end
  3. Somewhere in the middle of PHPcode I want to add an H3 title:

.

?><h3><?= $title ?></h3><?

Out of php and then back in. I’d rather write:

tag_wrap($title, 'h3');

or

h3($title);

Obviously I can write a library myself, but I would prefer to use a conventional way if there is one.

Edit

3 Might not be a good example – I don’t get much for using alternative syntax and I could have made it shorter.
1 and 2 are useful for debugging and quick testing.
I doubt that anyone would murder me for using some high-level html emitting functions of my own making when it saves a lot of writing.

  • 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-29T19:30:11+00:00Added an answer on May 29, 2026 at 7:30 pm

    In regards to #1, try xdebug‘s var_dump override, if you control your server and can install PHP extensions. The remote debugger and performance tools provided by xdebug are great additions to your arsenal. If you’re looking only for pure PHP code, consider Kint or dBug to supplement var_dump.

    In regards to #2 and #3, you don’t need to do this. Rather, you probably shouldn’t do this.

    PHP makes a fine HTML templating language. Trying to create functions to emit HTML is going to lead you down a horrible road of basically implementing the DOM in a horribly awkward and backwards way. Considering how horribly awkward the DOM already is, that’ll be quite an accomplishment. The future maintainers of your code are going to want to murder you for it.

    There is no shame in escaping out of PHP to emit large blocks of HTML. Escaping out to emit a single tag, though, is completely silly. Don’t do that, and don’t create functions that do that. There are better ways.

    First, don’t forget that print and echo aren’t functions, they’re built in to the language parser. Because they’re special snowflakes, they can take a list without parens. This can make some awkward HTML construction far less awkward. For example:

    echo '<select name="', htmlspecialchars($select_name), '</select>';
    foreach($list as $key => $value) {
        echo '<option value="',
             htmlspecialchars($key),
             '">',
             htmlspecialchars($value),
             '</option>'
    }
    echo '</select>';
    

    Next, PHP supports heredocs, a method of creating a double-quoted string without the double-quotes:

    $snippet = <<<HERE
    <h1>$heading</h1>
    <p>
        <span class="aside">$aside_content</span>
        $actual_content
    </p>    
    HERE;
    

    With these two tools in your arsenal, you may find yourself breaking out of PHP far less frequently.

    While there is a case for helper functions (there are only so many ways you can build a <select>, for example), you want to use these carefully and create them to reduce copy and paste, not simply to create them. The people that will be taking care of the code you’re writing five years from now will appreciate you for it.

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

Sidebar

Related Questions

Is there a standard library method that converts a string that has duration in
Is there any PHP PDF library that can replace placeholder variables in an existing
Is there any way to change standard output stream so that it is written
I know that there is a function in Java to set Standard Output Stream
Is there a de-facto standard library for creating ASCII tables in PHP? I want
Is there some standard way or has anyone written something that allows you to
Is there any possibility to achieve different redirections for standard output like printf(3) for
There are many java standard and 3rd party libraries that in their public API,
Is there an alternative to tee which captures standard output and standard error of
Is there any way to read standard output/error from any, GUI and non-GUI, already

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.