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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:11:52+00:00 2026-06-08T17:11:52+00:00

I combined HTML with PHP to generate a web page. My PHP code is:

  • 0

I combined HTML with PHP to generate a web page. My PHP code is:

public function generateSelect()
{
    $data = "<select>\n";

    for ($i = 2000;$i<=2012;$i++)
    {
        $data .= "\t<option value='$i'>$i</option>\n";
    }
    $data .= "</select>";
    $this->data = $data;
    return $this;
}

And this is my HTML:

<div>
    <?= $data ?>
</div>

And this is the result:

<div>
    <select>
    <option value='2000'>2000</option>
    <option value='2001'>2001</option>
    <option value='2002'>2002</option>
    <option value='2003'>2003</option>
    <option value='2004'>2004</option>
    <option value='2005'>2005</option>
    <option value='2006'>2006</option>
    <option value='2007'>2007</option>
    <option value='2008'>2008</option>
    <option value='2009'>2009</option>
    <option value='2010'>2010</option>
    <option value='2011'>2011</option>
    <option value='2012'>2012</option>
</select>
</div>

I know that it can be fixed with \t and \n. But I want to know if there is any way to do it automatically?

  • 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-08T17:11:53+00:00Added an answer on June 8, 2026 at 5:11 pm

    It can be done with PHP’s tidy class. As well as PHP’s DOM extension.

    <?php
    
        $html = <<<HTML
    <div>
        <select>
            <option value='2000'>2000</option>
            <option value='2001'>2001</option>
            <option value='2002'>2002</option>
            <option value='2003'>2003</option>
            <option value='2004'>2004</option>
            <option value='2005'>2005</option>
            <option value='2006'>2006</option>
            <option value='2007'>2007</option>
            <option value='2008'>2008</option>
            <option value='2009'>2009</option>
            <option value='2010'>2010</option>
            <option value='2011'>2011</option>
            <option value='2012'>2012</option>
        </select>
    </div>
    HTML;
    
        $dom = new DOMDocument();
        $dom->loadXML($html);
    
        $dom->formatOutput = true;
        echo $dom->saveHTML();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm submitting a form via HTML into a POST PHP page, which is then
Can hover and click functions be combined into one, so for example: click: $('#target').click(function()
Using jQuery UI 1.8rc3 combined with the new jquery.effects.fade.js code, I've been able to
I have some variables stored using php and an html textarea. I would like
If I want to combine asp.net code with html (mark up) file, I need
I have a some html being generated by JQuery on a Share Point page.
I have combined itechroom checkUserName function with JohnP's run js after user finished typing
I use Simple HTML DOM to scrape a page for the latest news, and
I am using Dompdf to generate A5 pdf documents from a html template and
I've been looking for some guidelines on how to layout PHP code. I've found

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.