Click to See Complete Forum and Search --> : Outputing Selected HTML


fvillena
09-06-2006, 08:41 AM
Hi Everyone

Basically I have an ASP page that outputs the content of an article from a database onto a page, the content is in HTML complete with <p> tags and so on and the user can also insert images etc.

My problem is that I want to only display the first two/three paragraphs of the article if a user has not logged in. If I just use Left(article,1000) or similar then it could cut off the content in the middle of an image tag etc.

I've put in code that goes through the content and finds the third closing </p> tag and use that for the position in the left statment which although okay I'm sure problems would arise in a real world scenario where say for some reason an article doesn't have any paragraph tags.

I don't want to strip the HTML tags from the content as I still want the first 3 paragraphs of the article to retain its formatting.

Any ideas would be greatly appreciated.

russell_g_1
09-06-2006, 02:00 PM
sounds tricky. suppose it would be possible to scan through your first 1000 chars and look for tags. when you find one you could add it to a list, and then when you find a matching close tag you could take it out. this would give you a list of tags that are still open, all you'd have to do is put the close tags in in the right order... maybe.

not sure how well this would work but sounds clever :)