You are not logged in.
This plugin allows you to cut a string of XHTML at a specific character limit, without causing invalid XHTML or utf8, unlike the sab_substr plugin which is meant for non HTML encoded plain text only.
Features:
Changelog:
Offline
Looks like this (yummy) testcase lets rvm_substr lose its ability to close tags:
$in = <<<EOT <h3>Zutaten für zwei Portionen</h3><ul> <li>150 g Dinkelflocken</li> <li>3 Eier</li> <li>150 g Emmentaler Käse</li> <li>Salz und Pfeffer</li> <li>3 Jungzwiebel</li> <li>Eine Knoblauchzehe</li> </ul><h3>Zubereitung</h3><ul> <li>Jungzwiebel hacken und anschwitzen</li> <li>Käse reiben und mit den Eiern, den Dinkelflocken und den Jungzwiebeln zu einer Teigmasse vermengen</li> <li>Die Knoblauchzehe in die Dinkelmasse drücken</li> <li>Die Masse salzen und pfeffern und danach 15 Minuten ruhen lassen</li> <li>Vier Laibchen formen und in goldbraun braten</li> </ul> EOT;$out = rvm_substr(array('length' => 350), $in);
Result in $out:
<h3>Zutaten für zwei Portionen</h3><ul> <li>150 g Dinkelflocken</li> <li>3 Eier</li> <li>150 g Emmentaler Käse</li> <li>Salz und Pfeffer</li> <li>3 Jungzwiebel</li> <li>Eine Knoblauchzehe</li> </ul><h3>Zubereitung</h3><ul> <li>Jungzwiebel hacken und anschwitzen</li> <li>Käse reiben und mit den Eiern, den Dinkelflocken und den Jungzwiebeln zu einer Teigmasse vermengen</li> <li>Die Knoblauchzehe in die Dinkelmasse drücken</li> <li>Die Masse salzen und pfeffern und danach 15…</i></l>
NB: the closing tags at the very end.
Expected result:

Try wet_quicklink | Me | @rwetzlmayr | +Robert Wetzlmayr | Repos
Offline
Thanks. Version 0.3 uploaded. It just needed a ) moved one character. The buggy version actually showed me something interesting. If you use a multi-matching () in PCRE, the last match is remembered. Not sure if that’s ‘last’ in a string-length context or ‘last’ in the actual pattern matching routine, although the latter is more likely.
Offline
Looks like there’s still a small bug in it:
<txp:link_to_prev><txp:rvm_substr length="20"><txp:prev_title /></txp:rvm_substr></txp:link_to_prev>
Results in: “The power and proble”
Instead of: “The power and proble…”
Any idea what might be causing this?
Textpattern projects: Maxvoltar, Made by Elephant, Twunch
Offline
Tim, did you install the latest version (0.3) of this plugin?
I just tested it and if the string is indeed longer than what is shown (for example: “The power and problem”), the ellipsis is added.
Offline
Offline
Nice plugin, Ruud!
I am looking for the option to have it cut off text before a certain character, instead of a specific character limit. I would like to select the first word (the one before the first comma) in the list of keywords for an article. Would that be possible to do?
• Photojournalist.jp – News and photos (100% txp)
• JapaneseStreets.com – Japanese street fashion (mostly txp)
• Old Photos of Japan – Japan between 1860 and 1940 (100% txp)
• MeijiShowa – Stock photos of Japan between 1860 and 1940 (100% txp)
Offline
Kjeld, that’s outside the scope of this plugin, but you can easily do it like this (not tested):
<txp:php>
// turn string of keywords into an array
$keywords = do_list($GLOBALS['thisarticle']['keywords']);
// if keywords exist, output the first keyword only
if ($keywords) echo htmlspecialchars($keywords[0]);
</txp:php>
Offline
Thanks for the plugin, Ruud.
I’m getting some extra html entities after the truncated title:
My Title ...
And I’m using this setup:
<txp:permlink><txp:sab_substr limit="35" trail="..."><txp:title /></txp:sab_substr></txp:permlink>
Last edited by Jaro (2009-11-08 19:45:04)
Offline