Documentation

Str
in package

Pop utils string helper class

Tags
category

Pop

author

Nick Sagona, III dev@nolainteractive.com

copyright

Copyright (c) 2009-2024 NOLA Interactive, LLC. (http://www.nolainteractive.com)

license

http://www.popphp.org/license New BSD License

version
2.1.0

Table of Contents

Constants

LOWERCASE  = 1
MIXEDCASE  = 0
Constants case type for random string generation
UPPERCASE  = 2

Properties

$allowedCases  : array<string|int, mixed>
Allowed keywords for converting cases
$linksRegex  : array<string|int, mixed>
Regex patterns & replacements for links
$randomChars  : array<string|int, mixed>
Characters for random string generation (certain characters omitted to eliminate confusion)

Methods

__callStatic()  : string
Convert a string from one case to another
convertFromCamelCase()  : string
Convert a camelCase string using the $separator value passed
convertToCamelCase()  : string
Convert a camelCase string using the $separator value passed
createLinks()  : string
Convert any links in the string to HTML links.
createRandom()  : string
Generate a random string of a predefined length.
createRandomAlpha()  : string
Generate a random alphabetical string of a predefined length.
createRandomAlphaNum()  : string
Generate a random alphanumeric string of a predefined length.
createRandomNumeric()  : string
Generate a random numeric string of a predefined length.
createSlug()  : string
Convert the string into an SEO-friendly slug.
detectSeparator()  : string
Attempt to detect separator
generateRandomString()  : string
Generate characters based on length and character sets provided

Constants

LOWERCASE

public mixed LOWERCASE = 1

MIXEDCASE

Constants case type for random string generation

public mixed MIXEDCASE = 0

UPPERCASE

public mixed UPPERCASE = 2

Properties

$allowedCases

Allowed keywords for converting cases

protected static array<string|int, mixed> $allowedCases = ['titlecase', 'camelcase', 'kebabcase', 'dash', 'snakecase', 'underscore', 'namespace', 'path', 'url', 'uri']

$linksRegex

Regex patterns & replacements for links

protected static array<string|int, mixed> $linksRegex = [['pattern' => '/(http|https|ftp|ftps)\\:\\/\\/[a-zA-Z0-9\\-\\.]+\\.[a-zA-Z]{2,3}(\\/\\S*)?/m', 'replacement' => '<a href="$0">$0</a>'], ['pattern' => '/[a-zA-Z0-9\\.\\-\\_+%]+@[a-zA-Z0-9\\-\\_\\.]+\\.[a-zA-Z]{2,4}/m', 'replacement' => '<a href="mailto:$0">$0</a>']]

$randomChars

Characters for random string generation (certain characters omitted to eliminate confusion)

protected static array<string|int, mixed> $randomChars = ['abcdefghjkmnpqrstuvwxyz', 'ABCDEFGHJKLMNPQRSTUVWXYZ', '0123456789', '!?#$%&@-_+*=,.:;()[]{}']

Methods

__callStatic()

Convert a string from one case to another

public static __callStatic(string $name, array<string|int, mixed> $arguments) : string
Parameters
$name : string
$arguments : array<string|int, mixed>
Return values
string

convertFromCamelCase()

Convert a camelCase string using the $separator value passed

public static convertFromCamelCase(string $string[, string|null $separator = null ][, bool $preserveCase = false ]) : string
Parameters
$string : string
$separator : string|null = null
$preserveCase : bool = false
Return values
string

convertToCamelCase()

Convert a camelCase string using the $separator value passed

public static convertToCamelCase(string $string[, string|null $separator = null ]) : string
Parameters
$string : string
$separator : string|null = null
Return values
string

Convert any links in the string to HTML links.

public static createLinks(string $string[, array<string|int, mixed> $attributes = [] ]) : string
Parameters
$string : string
$attributes : array<string|int, mixed> = []
Return values
string

createRandom()

Generate a random string of a predefined length.

public static createRandom(int $length[, int $case = self::MIXEDCASE ]) : string
Parameters
$length : int
$case : int = self::MIXEDCASE
Return values
string

createRandomAlpha()

Generate a random alphabetical string of a predefined length.

public static createRandomAlpha(int $length[, int $case = self::MIXEDCASE ]) : string
Parameters
$length : int
$case : int = self::MIXEDCASE
Return values
string

createRandomAlphaNum()

Generate a random alphanumeric string of a predefined length.

public static createRandomAlphaNum(int $length[, int $case = self::MIXEDCASE ]) : string
Parameters
$length : int
$case : int = self::MIXEDCASE
Return values
string

createRandomNumeric()

Generate a random numeric string of a predefined length.

public static createRandomNumeric(int $length) : string
Parameters
$length : int
Return values
string

createSlug()

Convert the string into an SEO-friendly slug.

public static createSlug(string $string[, string $separator = '-' ]) : string
Parameters
$string : string
$separator : string = '-'
Return values
string

detectSeparator()

Attempt to detect separator

public static detectSeparator(string $string) : string
Parameters
$string : string
Return values
string

generateRandomString()

Generate characters based on length and character sets provided

public static generateRandomString(int $length, array<string|int, mixed> $charsets) : string
Parameters
$length : int
$charsets : array<string|int, mixed>
Return values
string

        
On this page

Search results