Sitemagic CMS utility functions
This page briefly descriptions some useful helper/utility functions within Sitemagic CMS
Random
The
SMRandom class is useful for creating GUIDs (unique IDs) and random text strings and numbers.
// Create GUID - example: b98aa51f28b94dee9217faaad7c4cf5e
$guid = SMRandom::CreateGuid();
// Create random text for e.g. a password - example: jhgFokqK
$randomText = SMRandom::CreateText();
// Create random number (integer) between 0 and 25
$randomNumber = SMRandom::CreateNumber(0, 25);
String functions
The
SMStringUtilities class extends the string capabilities of PHP a bit.
// Validate string agains simple validation rule (returns true/false)
$isValid = SMStringUtiltilies::Validate($string, SMValueRestriction::$Numeric);
// Check whether a string starts with a given value (returns true/false)
$startsWith = SMStringUtilities::StartsWith($string, $search);
// Check whether a string ends with a given value (returns true/false)
$endsWith = SMStringUtilities::EndsWith($string, $search);
// Easily replace all or a number of occurences of a given value within a string.
// Unique to this function is its ability to search the string in a case insensitive manner
// as demonstrated below (given by the last argument).
$string = SMStringUtilities::Replace($string, $search, $replace, false);
// Easily split a given string using a delimiter that may occure with different casing.
$arr = SMStringUtilities::SplitCaseInsensitive($content, $delimiter);