This document lists all the functions available in the Valksor Functions: Text package.
public function camelCase(
string $string,
): stringConverts a string to camelCase format.
Parameters:
$string: The input string to convert
Returns the string in camelCase format (first word lowercase, subsequent words capitalized with no spaces or underscores).
public function pascalCase(
string $string,
): stringConverts a string to PascalCase format.
Parameters:
$string: The input string to convert
Returns the string in PascalCase format (all words capitalized with no spaces or underscores).
public function snakeCaseFromCamelCase(
string $string,
): stringConverts a camelCase string to snake_case format.
Parameters:
$string: The camelCase string to convert
Returns the string in snake_case format.
public function snakeCaseFromSentence(
string $string,
): stringConverts a sentence to snake_case format.
Parameters:
$string: The sentence to convert
Returns the string in snake_case format.
public function randomString(
int $length = 32,
string $chars = Functions::BASIC,
): stringGenerates a random string of the specified length using the given character set.
Parameters:
$length: The length of the random string (default: 32)$chars: The character set to use (default: lowercase and uppercase English letters plus digits)
Returns a random string of the specified length.
public function uniqueId(
string $prefix = '',
): stringGenerates a unique identifier with an optional prefix.
Parameters:
$prefix: Optional prefix for the unique ID
Returns a unique identifier string.
public function sanitize(
string $text,
): stringSanitizes text by removing HTML tags and converting quotes to HTML entities.
Parameters:
$text: The text to sanitize
Returns the sanitized text.
public function sanitizeFloat(
string $float,
): stringSanitizes a float string by ensuring it uses the correct decimal separator.
Parameters:
$float: The float string to sanitize
Returns the sanitized float string.
public function cleanText(
string $text,
): stringCleans text by removing unwanted characters and normalizing whitespace.
Parameters:
$text: The text to clean
Returns the cleaned text.
public function keepNumeric(
string $string,
): stringRemoves all non-numeric characters from a string.
Parameters:
$string: The input string
Returns a string containing only numeric characters.
public function stripSpace(
string $string,
): stringRemoves all whitespace characters from a string.
Parameters:
$string: The input string
Returns the string with all whitespace removed.
public function oneSpace(
string $string,
): stringReplaces multiple consecutive spaces with a single space.
Parameters:
$string: The input string
Returns the string with normalized spaces.
public function cyrillicToLatin(
string $text,
): stringConverts Cyrillic characters to their Latin equivalents.
Parameters:
$text: The text with Cyrillic characters
Returns the text with Cyrillic characters converted to Latin.
public function latinToCyrillic(
string $text,
): stringConverts Latin characters to their Cyrillic equivalents.
Parameters:
$text: The text with Latin characters
Returns the text with Latin characters converted to Cyrillic.
public function htmlEntityDecode(
string $string,
): stringDecodes HTML entities in a string.
Parameters:
$string: The string with HTML entities
Returns the decoded string.
public function br2nl(
string $string,
): stringConverts HTML line breaks to newlines.
Parameters:
$string: The string with HTML line breaks
Returns the string with HTML line breaks converted to newlines.
public function nl2br(
string $string,
): stringConverts newlines to HTML line breaks.
Parameters:
$string: The string with newlines
Returns the string with newlines converted to HTML line breaks.
public function limitChars(
string $text,
int $limit = 100,
string $append = '...',
): stringLimits the number of characters in a text and appends a suffix if truncated.
Parameters:
$text: The text to limit$limit: The maximum number of characters (default: 100)$append: The string to append if truncated (default: '...')
Returns the limited text.
public function limitWords(
string $text,
int $limit = 100,
string $append = '...',
): stringLimits the number of words in a text and appends a suffix if truncated.
Parameters:
$text: The text to limit$limit: The maximum number of words (default: 100)$append: The string to append if truncated (default: '...')
Returns the limited text.
public function truncateSafe(
string $string,
int $length,
string $append = '...',
): stringSafely truncates a string to a specified length without cutting words.
Parameters:
$string: The string to truncate$length: The maximum length$append: The string to append if truncated (default: '...')
Returns the safely truncated string.
public function reverseUTF8(
string $string,
): stringReverses a UTF-8 encoded string.
Parameters:
$string: The UTF-8 string to reverse
Returns the reversed string.
public function shuffle(
string $string,
): stringShuffles the characters in a string.
Parameters:
$string: The string to shuffle
Returns the shuffled string.
public function lastPart(
string $string,
string $delimiter,
): stringGets the last part of a string after the last occurrence of a delimiter.
Parameters:
$string: The input string$delimiter: The delimiter character
Returns the last part of the string.
public function contains(
string $haystack,
string $needle,
): boolChecks if a string contains a substring.
Parameters:
$haystack: The string to search in$needle: The substring to search for
Returns a boolean indicating whether the substring was found.
public function containsAny(
string $haystack,
array $needles,
): boolChecks if a string contains any of the given substrings.
Parameters:
$haystack: The string to search in$needles: An array of substrings to search for
Returns a boolean indicating whether any of the substrings were found.
public function strStartsWithAny(
string $haystack,
array $needles,
): boolChecks if a string starts with any of the given substrings.
Parameters:
$haystack: The string to check$needles: An array of possible prefixes to check for
Returns a boolean indicating whether the string starts with any of the given prefixes.
public function compare(
string $first,
string $second,
): boolCompares two strings for equality (case-insensitive).
Parameters:
$first: The first string$second: The second string
Returns a boolean indicating whether the strings are equal.
public function longestSubstrLength(
string $first,
string $second,
): intFinds the length of the longest common substring between two strings.
Parameters:
$first: The first string$second: The second string
Returns the length of the longest common substring.
public function isHex(
string $string,
): boolChecks if a string is a valid hexadecimal value.
Parameters:
$string: The string to check
Returns a boolean indicating whether the string is a valid hexadecimal value.
public function toString(
mixed $value,
): stringConverts a value to a string representation.
Parameters:
$value: The value to convert
Returns the string representation of the value.
public function scalarToString(
mixed $value,
): stringConverts a scalar value to a string.
Parameters:
$value: The scalar value to convert
Returns the string representation of the scalar value.
public function normalizedValue(
mixed $value,
): stringNormalizes a value to a standardized string representation.
Parameters:
$value: The value to normalize
Returns the normalized string representation.
public function pluralize(
string $singular,
): stringConverts a singular English word to its plural form.
Parameters:
$singular: The singular word
Returns the plural form of the word.
public function singularize(
string $plural,
): stringConverts a plural English word to its singular form.
Parameters:
$plural: The plural word
Returns the singular form of the word.
public function countryName(
string $code,
): stringGets the country name from a country code.
Parameters:
$code: The country code (ISO 3166-1 alpha-2)
Returns the country name.
public function sha(
string $string,
int $length = 40,
): stringGenerates a SHA hash of a string.
Parameters:
$string: The string to hash$length: The length of the hash (default: 40)
Returns the SHA hash.