Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re: Truncating HTML early

by nop (Hermit)
on Mar 18, 2002 at 18:59 UTC ( #152558=note: print w/replies, xml ) Need Help??

in reply to Truncating HTML early

Thanks, all for your excellent suggestions.

While working on this today, I had yet another idea, so I thought I'd share it here.

later edit by nop:
the following suggestion was not a good one --
leaving in empty tags creates HTML littered with empty bulleted lists, etc.
my final solution was to stop taking text after some limit of words, then use tidy to clean out the empty tags.

original post:
Assuming there's much text relative to markup, and assuming the markup is reasonably well-formed, an easy solution to this problem using HTML::Parser is count words in the text handler, and when that count exceeds a limit, have the handler stop appending new text to the result string. Allow the start and end handlers to continue adding their tags. The idea here is that when the text limit is reached, the rest of the markup (probably not much) will flow out empty.

This wouldn't be a good solution for html with heavy markup, but I think it may work in my case.......


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://152558]
NodeReaper does the danse macabre

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2017-09-23 07:57 GMT
Find Nodes?
    Voting Booth?
    During the recent solar eclipse, I:

    Results (272 votes). Check out past polls.