Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

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.
yuck.
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.......

nop


Comment on Re: Truncating HTML early

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://152558]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2014-09-17 05:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (58 votes), past polls