Hi perlmonks

I have a problem to solve and I would appreciated your help.

I have a txt file which contains one sentence per line and its html correspondence, and I would like to write in the html which line matches with what sentence in the html. Please note that in html one line may contain more than one sentences.

For example, my TXL file looks like:

This is sentence 1 This is sentence 2 This is sentence 1 This is sentence 3

And the html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <body> <p>This is sentence 1</p> <p>This is <font color="#000000"><font face="Century Gothic, serif">se +ntence 2</font></font></p> <p>This is sentence 1. This is sentence <span style="font-weight: norm +al">3</span> </p> </body> </html>

As you can see, the html file contains some extra html code, which makes things complex.

What I want to do is to add some html code and wrap the sentence:

<p><sentence id=”1”>This is sentence 1></sentence></p> <p><sentence id=”2”>This is <font color="#000000"><font face="Century +Gothic, serif">sentence 2</font></font></p></sentence> <p><sentence id=”3”>This is sentence 1. </sentence><sentence id=”4”>Th +is is sentence <span style="font-weight: normal">3</span></sentence>< +/p>

The order of the TXT corresponds to the order of the HTML. If no match found, then it should go to the next segment. Any ideas?

Thanks in advance for your help


In reply to Match text from txt to html by corfuitl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.