17488 Posts in 4473 Topics by 1978 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1692 Views |
-
HTMLText->Summary() does not work

25 May 2007 at 12:37pm
Hi,
when I use $Content.Summary(20) it always shows me the first paragraph, however long it is. When I have deleted this method from HTMLText, then is used Text->Summary(20) and it does what I expect.BTW. Why HTMLText is overloading only the Summary method, and not other ones like FirstSentence, FirstParagraph, BigSummary, ... ?
-
Re: HTMLText->Summary() does not work

25 May 2007 at 1:13pm
OK, I see HTMLText->Summary preserver HTML tags. So, here's my path:
--- HTMLText.php.orig 2007-05-25 13:00:18.000000000 +1200
+++ HTMLText.php 2007-05-25 13:09:17.000000000 +1200
@@ -33,13 +33,12 @@
}
elseif( preg_match( '/<\/(\w+)>/', $parts[$pIndex], $endTag ) && $endTag[1] == substr( $tagStack[count($tagStack) - 1], 1, strlen( $endTag[1] ) ) ) {
array_pop( $tagStack );
- $words++;
$summary .= $parts[$pIndex++];
} elseif( preg_match( '/^<\w+/', $parts[$pIndex] ) ) {
array_push( $tagStack, $parts[$pIndex] );
- $words++;
$summary .= $parts[$pIndex++];
} else {
+ $words++;
$summary .= $parts[$pIndex++] . ' ';
}
}
@@ -52,7 +51,11 @@
if(sizeof($tagName) > 0)
$summary .= "</{$tagName[1]}>";
}
-
+ // add triple dot and close the paragraph, if the paragraph has been trimmed
+ if ( $words > $maxWords || $pIndex >= count( $parts ) ) {
+ $summary .= '...</p>';
+ }
+
return $summary;
}Now, it seems to work well. Anyway, it would be nice to have other similar text manipulation methods from Text class also in HTMLText class.
-
Re: HTMLText->Summary() does not work

25 May 2007 at 2:58pm
Hmm, but if there's a picture in the first paragraph, like
<p><img ...></img></p>
then it shows only that picture. I am going to use the Text::Summary method.
| 1692 Views | ||
|
Page:
1
|
Go to Top |

