Str
class Str (View source)
The Str class holds all string methods.
Methods
Change format of a given date, optionally according to locale settings.
Set a default value for $str in case $str is empty.
Escapes a string to be used safely in a JSON string.
Find the URL of the first image within rendered HTML markup.
Find the first paragraph in rendered HTML and return its inner HTML.
Parse a markdown string. Optionally skip parsing in case $str is a single line string.
Perform a regex match.
Search and replace by regex.
Cleans up a string to be used as URL, directory or file name.
Shortens a string keeping full words. Note that this method also first strips all tags from the given string.
Strip substring from end of string.
Strip substring from start of string.
Removes all HTML and Markdown (!) tags.
Details
at line 72
static string
dateFormat(string $date, string $format, string $locale = false)
Change format of a given date, optionally according to locale settings.
In case a date variable is set in a txt file, its format can be different to a timestamp (mtime) of a file or page. To be independent on the given format without explicitly specifying it, strtotime() is used generate a proper input date. To use DateTime::createFromFormat() instead would require a third parameter (the original format) and would therefore make things more complicated than needed. The format can use either the date() or strftime() syntax. In case a locale is defined, the strftime() syntax has to be used. Multiple values can be passed as a CSV string for the locale parameter.
at line 108
static string
def(string $str, string $defaultValue)
Set a default value for $str in case $str is empty.
at line 126
static string
escape(string $str)
Escapes a string to be used safely in a JSON string.
at line 150
static string
findFirstImage(string $str)
Find the URL of the first image within rendered HTML markup.
at line 168
static string
findFirstParagraph(string $str)
Find the first paragraph in rendered HTML and return its inner HTML.
at line 189
static string
markdown(string $str, boolean $multilineOnly = false)
Parse a markdown string. Optionally skip parsing in case $str is a single line string.
at line 213
static number
match(string $str, string $regex)
Perform a regex match.
at line 229
static string
replace(string $str, string $regex, string $replace)
Search and replace by regex.
at line 250
static string
sanitize(string $str, boolean $removeDots = false, number $maxChars = 100)
Cleans up a string to be used as URL, directory or file name.
The returned string constists of the following characters: "a-z", "0-9", "-" and optional dots ".". That means, this method is safe to be used with filenames as well, since it keeps by default the dots as suffix separators.
Note: To produce fully safe prefixes and directory names, possible dots should be removed by setting $removeDots = true.
at line 287
static string
shorten(string $str, number $maxChars, string $ellipsis = ' ...')
Shortens a string keeping full words. Note that this method also first strips all tags from the given string.
at line 318
static string
stripEnd(string $str, string $end)
Strip substring from end of string.
at line 333
static string
stripStart(string $str, string $start)
Strip substring from start of string.
at line 347
static string
stripTags(string $str)
Removes all HTML and Markdown (!) tags.