[TYPO3-dev] cropHtml as new Feature for stdWrap

Martin Kutschker martin.kutschker-n0spam at no5pam-blackbox.net
Sun Jan 7 15:36:13 CET 2007


Steffen Kamper schrieb:
> Hi,
> 
> I developed a function that allows cropHtml taking care of open tags.
> I postet it here:
> http://bugs.typo3.org/view.php?id=4747

Is the output any different from strip_tags()? Besides it relies on the 
DOM XML functions which may not be availabe if you haven't installed the 
PECL lib.

Besides what IMHO would make more sense is a sensitive cropping. 
Basically there are two modes for cropping: crop to a given number of 
displayed characters (glyphs) or a number of bytes. In the latter case 
you must also take into account the character set (eg utf-8).

I will only address the former, suitable for content preview (eg news 
teaser or fulltext search results), which cares only about displayed 
characters and doesn't count the html tags.

What should be done is this assuming well formed (X)HTML:

Scan the content and count only the lengths of the text nodes. While 
doing this collect the opened tags on a stack. If the maximum character 
length is reached add the crop chars (eg "...") and close all open tags 
using the tag stack.

Masi




More information about the TYPO3-dev mailing list