MediaWiki master
|
A collection of static methods to play with strings. More...
Static Public Member Functions | |
static | delimiterExplode ( $startDelim, $endDelim, $separator, $subject, $nested=false) |
Explode a string, but ignore any instances of the separator inside the given start and end delimiters, which may optionally nest. | |
static | delimiterReplace ( $startDelim, $endDelim, $replace, $subject, $flags='') |
Perform an operation equivalent to preg_replace() with flags. | |
static | escapeRegexReplacement ( $string) |
Escape a string to make it suitable for inclusion in a preg_replace() replacement parameter. | |
static | explode ( $separator, $subject) |
Workalike for explode() with limited memory usage. | |
static | hungryDelimiterReplace ( $startDelim, $endDelim, $replace, $subject) |
Perform an operation equivalent to preg_replace() | |
static | isUtf8 ( $value) |
Test whether a string is valid UTF-8. | |
static | isValidPCRERegex ( $string) |
Utility function to check if the given string is a valid PCRE regex. | |
static | replaceMarkup ( $search, $replace, $text) |
More or less "markup-safe" str_replace() Ignores any instances of the separator inside <...> | |
static | unpack (string $format, string $data, $length=false) |
Wrapper around php's unpack. | |
A collection of static methods to play with strings.
Definition at line 31 of file StringUtils.php.
|
static |
Explode a string, but ignore any instances of the separator inside the given start and end delimiters, which may optionally nest.
The delimiters are literal strings, not regular expressions.
string | $startDelim | Start delimiter |
string | $endDelim | End delimiter |
string | $separator | Separator string for the explode. |
string | $subject | Subject string to explode. |
bool | $nested | True iff the delimiters are allowed to nest. |
Definition at line 61 of file StringUtils.php.
|
static |
Perform an operation equivalent to preg_replace()
with flags.
Matches this code:
preg_replace( "!$startDelim(.*)$endDelim!$flags", $replace, $subject );
string | $startDelim | Start delimiter regular expression |
string | $endDelim | End delimiter regular expression |
string | $replace | Replacement string. May contain $1, which will be replaced by the text between the delimiters |
string | $subject | String to search |
string | $flags | Regular expression flags |
Definition at line 249 of file StringUtils.php.
References $matches.
|
static |
Escape a string to make it suitable for inclusion in a preg_replace() replacement parameter.
string | $string |
Definition at line 315 of file StringUtils.php.
|
static |
Workalike for explode() with limited memory usage.
string | $separator | |
string | $subject |
Definition at line 327 of file StringUtils.php.
References explode().
Referenced by explode(), and hungryDelimiterReplace().
|
static |
Perform an operation equivalent to preg_replace()
Matches this code:
preg_replace( "!$startDelim(.*?)$endDelim!", $replace, $subject );
..except that it's worst-case O(N) instead of O(N^2). Compared to delimiterReplace(), this implementation is fast but memory-hungry and inflexible. The memory requirements are such that I don't recommend using it on anything but guaranteed small chunks of text.
string | $startDelim | |
string | $endDelim | |
string | $replace | |
string | $subject |
Definition at line 120 of file StringUtils.php.
References explode().
|
static |
Test whether a string is valid UTF-8.
The function check for invalid byte sequences, overlong encoding but not for different normalisations.
string | $value | String to check |
Definition at line 46 of file StringUtils.php.
|
static |
Utility function to check if the given string is a valid PCRE regex.
Avoids manually calling suppressWarnings and restoreWarnings, and provides a one-line solution without the need to use .
string | $string | The string you want to check being a valid regex |
Definition at line 300 of file StringUtils.php.
|
static |
More or less "markup-safe" str_replace() Ignores any instances of the separator inside <...>
string | $search | |
string | $replace | |
string | $text |
Definition at line 269 of file StringUtils.php.
References $matches.
|
static |
Wrapper around php's unpack.
string | $format | The format string (See php's docs) |
string | $data | A binary string of binary data |
int | false | $length | The minimum length of $data or false. This is to prevent reading beyond the end of $data. false to disable the check. |
Also be careful when using this function to read unsigned 32 bit integer because php might make it negative.
UnpackFailedException | If $data not long enough, or if unpack fails |
Definition at line 350 of file StringUtils.php.