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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T21:39:59+00:00 2026-05-13T21:39:59+00:00

How would I split a HTML formatted file into several HTML files (complete with

  • 0

How would I split a HTML formatted file into several HTML files (complete with with HTML, HEAD and BODY tags) with PHP? I would have a placeholder tag (something like <div class='placeholder'></div> ) for all the places I want to cut.

Thanks.

  • 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-13T21:39:59+00:00Added an answer on May 13, 2026 at 9:39 pm
    $sourceHTML = file_get_contents('sourcefile');
    
    $splitContents = explode("<div class='placeholder'></div>", $sourceHTML);
    
    foreach ($splitContents as $html) {
        // save html to file
    }
    

    Edit: whoops. As user201140 correctly points out, I missed the fact that each html file has to be a valid document. Since it’s not specified exactly what the head tag should contain, I’ll assume that the head tag of the combined document should be replicated to each copy. In that case:

    $sourceHTML = file_get_contents('sourcefile');
    preg_match("/(^.*<body.*?>)(.*)(<\/body.*$)/is", $sourceHTML, &$matches);
    $top = $matches[1];
    $contents = $matches[2];
    $bottom = $matches[3];
    $splitContents = explode("<div class='placeholder'></div>", $contents);
    foreach ($splitContents as $chunk) {
        $html = $top.$chunk.$bottom;
        // save html to file
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 490k
  • Answers 490k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer It seems you're asking for a Full Text Index, which… May 16, 2026 at 9:10 am
  • Editorial Team
    Editorial Team added an answer Try using: #define RESETCOLOR "\033[0m" That should reset it to… May 16, 2026 at 9:10 am
  • Editorial Team
    Editorial Team added an answer [NSTask launchedTaskWithLaunchPath:@"thisCMD" arguments:[NSArray arrayWithObject:username]]; Or if username isn't already a… May 16, 2026 at 9:10 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I'm relatively new to Clojure and a complete HTML/Compojure virgin. I'm trying to use
In my web application I intend to shorten a lengthy string of HTML formatted
I have a string that represents a non indented XML that I would like
How would I go about doing a query that returns results of all rows
I try to make my evoque templates color-code a bit, but the html I
I'm making a Wordpress 2.9.2 theme, and I'd like each page to have its
I'm working on a Markdown command line program, and I'd like to format source
I've written a fairly simple script that will take elements (in this case, <p>
I am interested in using jQuery to create automatic pagination for content based on

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.