I'm trying to extract the beginning of an HTML string, in a way that returns legal HTML, basically to generate a summary page of blog entries for the index. For an example entry

First a technological update - The code that drives this site is avail +able for free on <a href="https://github.com/amacks/vatican_mss">GitH +ub</a>. I've just merged in a rather complex change to create proper + shelfmark sorting, fixing things like numbers-stored-as-strings and +handling roman numerals. Two problems yet unfixed are Fonds <strong> +P.I.O</strong>, with the middle "I" reading as a roman numeral, and < +strong>Arch.Cap.S.Pietro</strong> where sub-set "I" is read as roman +1 and everything gets confused.</p>...

a naive perl substr($_,0,100), returns text ending "free on <a href="htt", which is bad


In reply to Truncate HTML String by amacks

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.