Trim the HTML and save content to txt file

Hello there,

I have a large HTML file, that looks like this:

[code]

Paragraph 1

1

text, text

More text, text

More text, text, text

Paragraph 2

1

text, text

More text, text

More text, text, text

....etc...[/code] I want to save content of each section in new .txt file, so I have txt files named with a content of "title" element (for example: Paragraph 1.txt, Paragraph 2.txt etc) and the content of first file should be everything under the first title class, upto the next "title" tag.

So the example for the above code should be:
Filename: Paragraph 1.txt
Content:

<p class="number">1</p>
<p class="normal">text, text</p>
<p class="normal">More text, text</p>
<p class="normal">More text, text, text</p>

Do note that sometimes there’s 3 “normal” classes in P tag, sometimes more, it’s not the same length for each paragraph.

Any suggestions?

read the file normally (fopen, while loop over rows). have some check (substring, regex) to see if the line is a class title, based on that decide what to do

Sponsor our Newsletter | Privacy Policy | Terms of Service