StringUtils
in package
String manipulation utilities.
Provides static methods for encoding strings, creating CSS class names, and handling translation separators.
Tags
Table of Contents
Properties
- $firstSeparator : string|null
- Cached first separator character.
- $separators : string|null
- Cached separators value (preg_quote'd).
Methods
- encodeURI() : string
- Encode a URI string matching JavaScript's encodeURI behavior.
- getFilePath() : string
- Get the path of a file using the theme directory.
- getFirstSeparator() : string
- Get the first translation separator character.
- getSeparators() : string
- Get the translation separators pattern for regex use.
- makeCounterWithTotal() : string
- Create a counter string with total (e.g., "01/10").
- parseInlineMarkdown() : string
- Parse inline Markdown to HTML.
- printFilePath() : void
- Echo the path of a file using the theme directory.
- removeSoftHyphens() : string
- Remove soft hyphens from a string.
- removeSpaces() : string
- Remove all spaces from a string.
- replaceFirst() : string
- Replace the first occurrence of $needle in $haystack with $replace.
- resetSeparatorCache() : void
- Reset cached separator values.
- toClassName() : string
- Escape a string for use as a CSS class name.
- toHex() : string
- Convert a string to hexadecimal representation.
Properties
$firstSeparator
Cached first separator character.
private
static string|null
$firstSeparator
= null
$separators
Cached separators value (preg_quote'd).
private
static string|null
$separators
= null
Methods
encodeURI()
Encode a URI string matching JavaScript's encodeURI behavior.
public
static encodeURI(string $url) : string
Parameters
- $url : string
-
URL to encode
Return values
string —Encoded URL
getFilePath()
Get the path of a file using the theme directory.
public
static getFilePath(string $filename) : string
Maps legacy paths to new asset locations:
- css/* -> assets/css/*
- icn/* -> assets/icons/*
- img/* -> assets/images/*
- js/* -> assets/js/*
Parameters
- $filename : string
-
Filename
Return values
string —File path if it exists, otherwise the filename
getFirstSeparator()
Get the first translation separator character.
public
static getFirstSeparator() : string
Return values
string —First separator character
getSeparators()
Get the translation separators pattern for regex use.
public
static getSeparators() : string
Returns the separator characters from settings, escaped for use in preg_split and similar functions.
Return values
string —Preg-quoted separator characters
makeCounterWithTotal()
Create a counter string with total (e.g., "01/10").
public
static makeCounterWithTotal(int $max, int $num) : string
Parameters
- $max : int
-
Total count
- $num : int
-
Current number
Return values
string —Formatted counter string
parseInlineMarkdown()
Parse inline Markdown to HTML.
public
static parseInlineMarkdown(string $text) : string
Supports: bold, italic, links, ~~strikethrough~~
Security:
Parameters
- $text : string
-
Input text with Markdown
Return values
string —HTML string
printFilePath()
Echo the path of a file using the theme directory.
public
static printFilePath(string $filename) : void
Parameters
- $filename : string
-
Filename
removeSoftHyphens()
Remove soft hyphens from a string.
public
static removeSoftHyphens(string $str) : string
Parameters
- $str : string
-
Input string
Return values
string —String without soft hyphens
removeSpaces()
Remove all spaces from a string.
public
static removeSpaces(string $s, string|bool|int $remove) : string
Parameters
- $s : string
-
Input string
- $remove : string|bool|int
-
Do not do anything if empty, false, or 0
Return values
string —String without spaces if requested
replaceFirst()
Replace the first occurrence of $needle in $haystack with $replace.
public
static replaceFirst(string $needle, string $replace, string $haystack) : string
Parameters
- $needle : string
-
Text to replace
- $replace : string
-
Replacement text
- $haystack : string
-
Input string
Return values
string —String with first occurrence replaced
resetSeparatorCache()
Reset cached separator values.
public
static resetSeparatorCache() : void
Call this if settings change during runtime.
toClassName()
Escape a string for use as a CSS class name.
public
static toClassName(string $string) : string
Escapes everything to "¤xx" (where xx is hex) except:
- 0-9 (ASCII 48-57)
- a-z (ASCII 97-122)
- A-Z (ASCII 65-90)
- Unicode characters >= 165 (hex 00A5)
Parameters
- $string : string
-
String to escape
Return values
string —CSS-safe class name
toHex()
Convert a string to hexadecimal representation.
public
static toHex(string $string) : string
Parameters
- $string : string
-
String to convert
Return values
string —Uppercase hexadecimal string