Template:Listify

From A KoL Wiki
<phptag>if (count($argv)>1) {

$err=""; if (isset($argv[2])) { $splt = $argv[2]; if (!$splt) { $splt="\n"; $err='<span style="color:red;">Cannot have a blank split argument</span>'; } } else { $splt = "\n"; } if (isset($argv["prefix"])) { $prefix = $argv["prefix"]; } else { $prefix = ""; } if (isset($argv["suffix"])) { $suffix = $argv["suffix"]; } else { $suffix = ""; } $a = explode($splt,trim($argv[1])); $m = count($a); if (isset($argv["list"])) { $pref = $argv["list"]; } else { $pref = "* "; } if (isset($argv["tag"])) { $ht = preg_quote($argv["tag"]); } else { $ht = null; } for ($i=0;$i<$m;$i++) { $x = $a[$i]; if ($ht !== null) { $hta = array(); if (preg_match('/#' . $ht . '\s*([^#]*)/',$x,$hta)==1) $x = $hta[1]; } echo $pref . $prefix . $x . $suffix; if ($i<$m-1) echo "\n"; } echo $err;

}</phptag>

Converts the given text into a list, by default with each line a new item.

Usage

  • Several optional arguments can be used:
    • The list= argument lets you specify a different list operator to be prepended to each line (default is "*").
    • The tag= argument will show only the value for the given tag.
    • If a second unnamed argument is given, it specifies the string used to break up the list (default is a newline).
    • The prefix= and suffix= arguments specify strings that will prefix and/or suffix each list value.