1 {{Extension|templatemode=
2 |name = StringFunctionsEscaped
4 |type1 = parser function
6 |hook1 = LanguageGetMagic
8 |username = [[user:jpond | Jack D. Pond ]]
10 |description = Defines a superset of string parser functions that allow character escaping in the 'search for' and 'replace with' arguments.
15 |mediawiki = Tested with 1.14,1.15,1.16A, Should work with all
17 |license = GNU Version 2
21 |parameters = $wgPFEnableStringFunctions
30 ==What can this extension do?==
32 Wikitext allows the imbedding of certain control characters (newline, tab, etc.). These parser functions allow them to be identified and used with standard c-type escape character sequence (/n,/t, etc.).
34 These can be used (among other things) to make infoblox-type templates much more WYSIWIG (see Examples) for novice/non-technical users.
38 These functions are all invoked exactly as their string parser functions would be (except with the '_e' appended to distinguish).
40 === pos_e: (string position)===
42 <nowiki>{{#pos_e:value|key|offset}}</nowiki>
44 Returns the first position of key inside the given value, or an empty string.
45 If offset is defined, this method will not search the first offset characters.
47 See: http://php.net/manual/function.strpos.php
49 === rpos_e: (string position, reverse) ===
50 <nowiki>{{#rpos_e:value|key}}</nowiki>
51 Returns the last position of key inside the given value, or -1 if the key is not found. When using this to search for the last delimiter, add +1 to the result to retreive position after the last delimiter. This also works when the delimiter is not found, because "-1 + 1" is zero, which is the beginning of the given value.
53 See: http://php.net/manual/function.strrpos.php
55 === pad_e: (pad string) ===
56 <nowiki>{{#pad_e:value|length|with|direction}}</nowiki>
58 Returns the value padded to the certain length with the given with string.
59 If the with string is not given, spaces are used for padding. The direction may be specified as: 'left', 'center' or 'right'.
61 See: http://php.net/manual/function.str-pad.php
63 === replace_e: (string replace) ===
65 <nowiki>{{#replace_e:value|from|to}}</nowiki>
67 Returns the given value with all occurences of 'from' replaced with 'to'.
69 See: http://php.net/manual/function.str-replace.php
71 === explode_e: (explode string) ===
72 <nowiki>{{#explode_e:value|delimiter|position}}</nowiki>
74 Splits the given value into pieces by the given delimiter and returns the position-th piece. Empty string is returned if there are not enough pieces.
76 Note: Pieces are counted from 0.<br>
77 Note: A negative value can be used to count pieces from the end, instead of counting from the beginning. The last piece is at position -1.
79 See: http://php.net/manual/function.explode.php
81 ==Download instructions==
82 <!-- revise these instructions if code is available via a download site -->
83 Please cut and paste the code found [[#Code|below]] and place it in <code>$IP/extensions/ExtensionName/ExtensionName.php</code>. ''Note: [[Manual:$IP|$IP]] stands for the root directory of your MediaWiki installation, the same directory that holds [[Manual:LocalSettings.php|LocalSettings.php]]''.
86 String functions were integrated into [[Extension:ParserFunctions]] extension as of [[Special:Code/MediaWiki/50997|r50997]]. This revision of [[Extension:ParserFunctions]] is designed for MediaWiki 1.16, but updating to the trunk version may work on previous versions. If you are using a prior version of [[Extension:ParserFunctions]], you will also have to include [[Extension:StringFunctions]].
88 Install and test [[Extension:ParserFunctions]] and (if necessary) [[Extension:StringFunctions]] prior to installing this extension.
90 This extension must be included AFTER the invocation of the string parser functions.
91 To install this extension, add the following to [[Manual:LocalSettings.php|LocalSettings.php]]:
93 === For MediaWiki 1.15.1 and before ===
95 require_once("$IP/extensions/ParserFunctions/ParserFunctions.php");
96 require_once("$IP/extensions/StringFunctions/StringFunctions.php");
97 require_once("$IP/extensions/StringFunctionsEscaped/StringFunctionsEscaped.php");
100 === For MediaWiki 1.16a and after ===
102 require_once("$IP/extensions/ParserFunctions/ParserFunctions.php");
103 $wgPFEnableStringFunctions = true; // Note: this must be after ParserFunctions and before StringFunctionsEscaped
104 require_once("$IP/extensions/StringFunctionsEscaped/StringFunctionsEscaped.php");
133 ~~{{#pad_e:xox|9|\n|center}}~~
158 Which would display as:
164 Rather than the unescaped:
183 * [[Extension:ParserFunctions]]
184 * [[Extension:StringFunctions]]