CRM_Utils_String
class CRM_Utils_String
This class contains string functions.
Constants
COMMA |
|
SEMICOLON |
|
SPACE |
|
TAB |
|
LINEFEED |
|
CARRIAGELINE |
|
LINECARRIAGE |
|
CARRIAGERETURN |
|
ALPHANUMERIC |
List of all letters and numbers |
Methods
Convert a display name into a potential variable name.
Replace all non alpha numeric characters and spaces with the replacement character.
Convert possibly underscore separated words to camel case with special handling for 'UF' e.g membership_payment returns MembershipPayment
Takes a variable name and munges it randomly into another variable name.
Takes a string and returns the last tuple of the string.
Appends a name to a string and separated by delimiter.
Determine if the string is composed only of ascii characters.
Determine the string replacements for redaction.
No description
Determine if a string is composed only of utf8 characters
Determine if two hrefs are equivalent (fuzzy match)
Extract the civicrm path from the url.
Translate a true/false/yes/no string to a 0 or 1 value
Returns string '1' for a true/yes/1 string, and '0' for no/false/0 else returns false
Convert a HTML string into a text one using html2text
No description
No description
Given an ezComponents-parsed representation of a text with alternatives return only the first one
Strip leading, trailing, double spaces from string used for postal/greeting/addressee
clean the URL 'path' variable that we use to construct CiviCRM urls by removing characters from the path variable
Use HTMLPurifier to clean up a text string and remove any potential xss attacks. This is primarily used in public facing pages which accept html as the input string
Truncate $string; if $string exceeds $maxLen, place ".
Generate a random string.
Examples: "admin foo" => array(NULL,"admin foo") "cms:admin foo" => array("cms", "admin foo")
This function will mask part of the the user portion of an Email address (everything before the @)
This function compares two strings.
Many parts of the codebase have a convention of internally passing around HTML-encoded URLs. This effectively means that "&" is replaced by "&" (because most other odd characters are %-escaped in URLs; and %-escaped strings don't need any extra escaping in HTML).
When a user supplies a URL (e.g. to an image), we'd like to: - Remove the protocol and domain name if the URL points to the current site.
A simplified version of PHP's parse_url() function.
Formats a string of attributes for insertion in an html tag.
Determine if $string starts with $fragment.
Determine if $string ends with $fragment.
No description
Safely unserialize a string of scalar or array values (but not objects!)
Details
at line 59
static string
titleToVar(string $title, int $maxLength = 31)
Convert a display name into a potential variable name.
at line 84
static string
munge(string $name, string $char = '_', int $len = 63)
Replace all non alpha numeric characters and spaces with the replacement character.
at line 112
static string
convertStringToCamel(string $string)
Convert possibly underscore separated words to camel case with special handling for 'UF' e.g membership_payment returns MembershipPayment
at line 149
static string
rename(string $name, int $len = 4)
Takes a variable name and munges it randomly into another variable name.
at line 167
static string
getClassName(string $string, string $char = '_')
Takes a string and returns the last tuple of the string.
Useful while converting file names to class names etc
at line 189
static
append(string $str, string $delim, mixed $name)
Appends a name to a string and separated by delimiter.
Does the right thing for an empty string
at line 228
static bool
isAscii(string $str, bool $utf8 = TRUE)
Determine if the string is composed only of ascii characters.
at line 272
static array
regex(string $str, array $regexRules)
Determine the string replacements for redaction.
on the basis of the regular expressions
at line 310
static mixed
redaction($str, $stringRules)
at line 330
static bool
isUtf8(string $str)
Determine if a string is composed only of utf8 characters
at line 359
static bool
match(string $url1, string $url2)
Determine if two hrefs are equivalent (fuzzy match)
at line 383
static string|null
extractURLVarValue(string $query)
Extract the civicrm path from the url.
at line 407
static bool
strtobool(string $str)
Translate a true/false/yes/no string to a 0 or 1 value
at line 426
static bool
strtoboolstr(string $str)
Returns string '1' for a true/yes/1 string, and '0' for no/false/0 else returns false
at line 451
static string
htmlToText(string $html)
Convert a HTML string into a text one using html2text
at line 464
static
extractName($string, array $params)
at line 519
static array
makeArray($string)
at line 543
static string
stripAlternatives(string $full)
Given an ezComponents-parsed representation of a text with alternatives return only the first one
at line 567
static string
stripSpaces(string $string)
Strip leading, trailing, double spaces from string used for postal/greeting/addressee
at line 585
static string
stripPathChars(string $string, array $search = NULL, string $replace = NULL)
clean the URL 'path' variable that we use to construct CiviCRM urls by removing characters from the path variable
at line 642
static string
purifyHTML(string $string)
Use HTMLPurifier to clean up a text string and remove any potential xss attacks. This is primarily used in public facing pages which accept html as the input string
at line 666
static string
ellipsify(string $string, int $maxLen)
Truncate $string; if $string exceeds $maxLen, place ".
.." at the end
at line 680
static string
createRandom($len, $alphabet)
Generate a random string.
at line 702
static array
parsePrefix($delim, string $string, null $defaultPrefix = NULL)
Examples: "admin foo" => array(NULL,"admin foo") "cms:admin foo" => array("cms", "admin foo")
at line 725
static string
maskEmail(string $email, string $maskChar = '*', int $percent = 50)
This function will mask part of the the user portion of an Email address (everything before the @)
at line 751
static bool
compareStr(string $strOne, string $strTwo, bool $case)
This function compares two strings.
at line 787
static string
unstupifyUrl(string $htmlUrl)
Many parts of the codebase have a convention of internally passing around HTML-encoded URLs. This effectively means that "&" is replaced by "&" (because most other odd characters are %-escaped in URLs; and %-escaped strings don't need any extra escaping in HTML).
at line 819
static string
simplifyURL(string $url, bool $forceHttps = FALSE)
When a user supplies a URL (e.g. to an image), we'd like to: - Remove the protocol and domain name if the URL points to the current site.
- Keep the domain name for remote URLs.
- Optionally, force remote URLs to use https instead of http (which is useful for images)
at line 853
static array
simpleParseUrl(string $url)
A simplified version of PHP's parse_url() function.
at line 872
static string
htmlAttributes(array $attributes)
Formats a string of attributes for insertion in an html tag.
at line 889
static bool
startsWith(string $string, string $fragment)
Determine if $string starts with $fragment.
at line 906
static bool
endsWith(string $string, string $fragment)
Determine if $string ends with $fragment.
at line 921
static array
filterByWildcards(string|array $patterns, array $allStrings, bool $allowNew = FALSE)
at line 959
static mixed
unserialize(string|NULL $string)
Safely unserialize a string of scalar or array values (but not objects!)
Use xkerman/restricted-unserialize
to unserialize strings using PHP's
serialization format. restricted-unserialize
works like PHP's built-in
unserialize
function except that it does not deserialize object instances,
making it immune to PHP Object Injection {see https://www.owasp.org/index.php/PHP_Object_Injection}
vulnerabilities.
Note: When dealing with user inputs, it is generally recommended to use safe, standard data interchange formats such as JSON rather than PHP's serialization format when dealing with user input.