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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T22:35:10+00:00 2026-06-04T22:35:10+00:00

How to generate HTML files depends on array length php I have an XML

  • 0

How to generate HTML files depends on array length php

I have an XML file.

<books>
  <book x="1" y="2">
     <name x="5" y="12">Java</name>
     <author x="8" y="16">Rao</author>
   </book>
   <book x="12" y="20">
     <name x="5" y="12">Php</name>
     <author x="5" y="12">Naidu</author>
   </book>
   <book x="19" y="29">
     <name x="25" y="22">Xml</name>
     <author x="25" y="12">Gowda</author>
   </book>
</books>

I have converted it into array using php.

I have standard html files i.e template.

<body>
  <div id="books" style="float:right; position:absolute; left: 199px; top: 245px;">
    <div id="book" style="float:right; position:absolute; left: 199px; top: 245px;">
    <div id="name" style="float:right; position:absolute; left: 199px; top: 245px;"></div>
    <div id="author" style="float:right; position:absolute; left: 199px; top: 245px;"></div>
     </div>
   </div>
</body>

Based on the array legth, I need to generate those many html files with dynamic values inside the div which are present in array .
Here i need to generate 3 html files (because i have 3 book elements).How can i generate the html files by using array.

array is look like this:

Array
(
    [book] => Array
        (
            [0] => Array
                (
                    [name] => Java
                    [author] => Rao
                    [@attributes] => Array
                        (
                            [x] => 1
                            [y] => 2
                        )

                )

            [1] => Array
                (
                    [name] => Php
                    [author] => Naidu
                    [@attributes] => Array
                        (
                            [x] => 12
                            [y] => 20
                        )

                )

            [2] => Array
                (
                    [name] => Xml
                    [author] => Gowda
                    [@attributes] => Array
                        (
                            [x] => 19
                            [y] => 29
                        )

                )

        )

)
  • 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-04T22:35:12+00:00Added an answer on June 4, 2026 at 10:35 pm

    In your html template, use delimiters like real-template :

    <body>
        <div id="books" style="float:right; position:absolute; left: 199px; top: 245px;">
            <div id="book" style="float:right; position:absolute; left: 199px; top: 245px;">
                <div id="name" style="float:right; position:absolute; left: 199px; top: 245px;">{name}</div>
                <div id="author" style="float:right; position:absolute; left: 199px; top: 245px;">{author}</div>
            </div>
        </div>
    </body>
    

    In the PHP-side, use regexp to replace data in your template :

            $html_template = file_get_contents('/path/to/your/html/template');
    
            foreach($books['book'] as $i => $book) {
                $file_name = "html_page_for_book_{$i}";
                $html_file = fopen($file_name,'w');
    
                $html_data = preg_replace(array('/{author}/','/{name}/'),array($book['author'],$book['name']),$html_template);
                fwrite($html_file,$html_data);
    
                fclose($html_file);
    
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following XML from which I am trying to generate HTML files.
I have a bunch of XML files which I use to generate HTML pages.
I have a .NET console application that needs to generate some HTML files. I
I am having a php file which executes some code to generate a html
I am transforming following XML to generate HTML. XML <clause code=section6> <variable col=1 name=R1C1
I need some help with priviligies in centos I have a file in home/admin/public_html/generate.php
I have a multiple html files in one file. <html> <body></body> </html> <html> <body></body>
I have a Java string of XML content. I use Velocity to generate some
My Java Swing application generates an HTML file, and I want to open it
The content of the an HTML file generated by a PHP is stored in

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.