StringUtils Class
Simple utilities for formatting strings. Located in the namespace Canteen\Utilities.
Item Index
Methods
- checkBacktrackLimit static
- convertPropertyToConst static
- fnmatchInArray static
- generateRandomString static
- isRegex static
- isSerialized static
- minify static
- multilineEdit static
- multilineSave static
- propertyToReadable static
- replaceOnce static
- requireSeparator static
- stripBuffer static
- uriToMethodCall static
Methods
checkBacktrackLimit
-
string
The default backtrack limit for preg expressions is 100KB, we may have pages which ar larger than 100,000, and need to increase the pcre.backtrack_limit
Parameters:
-
string
StringThe string to limit test
convertPropertyToConst
-
property
Convert a property name (someProperty to const SOME_PROPERTY)
Parameters:
-
property
StringThe property name
Returns:
The property name as a constant name format
fnmatchInArray
-
needle
-
haystack
Works like in_array but uses native fnmatch
Returns:
If the string is found in the array
generateRandomString
-
[length=8]
Get a random string of characters (readable-ish format)
Parameters:
-
[length=8]
Int optionalThe length of the string to export
Returns:
The string of random characters
isRegex
-
str
Test a string to see if it's a regular expression
Parameters:
-
str
Stringthe string to test
Returns:
If the string is a regular expression
isSerialized
-
value
-
[result=null]
Check to see if a string is serialized, if it is return result
Parameters:
-
value
StringValue to test for serialized form
-
[result=null]
Mixed optionalResult of unserialize() of the $value
Returns:
True if value is serialized data, otherwise false
minify
-
buffer
Used to remove extra whitespace from a buffer Respects the textareas
Parameters:
-
buffer
StringThe output buffer
Returns:
The minified HTML string, remove extra whitespace and returns
multilineEdit
-
content
Convert multiline text to be displayed within a textarea for editting
Parameters:
-
content
StringThe content to update
Returns:
The editable content
multilineSave
-
content
Convert multiline text to be saved to the database for markup display
Parameters:
-
content
StringThe content to save
Returns:
The editable content
propertyToReadable
-
property
Convert a property name (myProperty) to a readable name (My Property)
Parameters:
-
property
StringThe name of the property (lower camel-case)
Returns:
The readable name, title-case
replaceOnce
-
search
-
replace
-
subject
Replace the first occurrence in a string
Parameters:
Returns:
The result after replacement
requireSeparator
-
directory
Makes sure to include the trailing slash for a directory path
Parameters:
-
directory
StringThe directory path
Returns:
The directory path with included trailing slash