Skip to content

Latest commit

 

History

History
700 lines (381 loc) · 9.11 KB

Str.md

File metadata and controls

700 lines (381 loc) · 9.11 KB

JW3B\Helpful\Str

Some of these functions have been influenced by Laravels Str class

Methods

Name Description
camel Convert a value to camel case.
clean_url Clean a URL string.
e Clean a text string.
form_element_name Generate a form element name from a string.
fromBase64 Decode the given Base64 encoded string.
headline Convert various string formats to a capitalized headline.
kebab Convert a camelCase string to kebab-case.
lcfirst Make a string's first character lowercase.
length Return the length of the given string.
limit Limit the number of characters in a string.
lower Convert the given string to lower-case.
ltrim Remove all whitespace from the beginning of a string.
p Print a variable in a readable format.
parse_my_url Parse the current URL into an array of segments.
randomString Generate a random string.
removePound Remove pound signs and dashes from a string.
rtrim Remove all whitespace from the end of a string.
snake Convert a string to snake case.
studly Convert a value to studly caps case.
substr Returns the portion of the string specified by the start and length parameters.
swap Swap keywords in a string according to a mapping array.
title Convert the given string to proper case.
toBase64 Convert the given string to Base64 encoding.
trim Remove all whitespace from both ends of a string.
ucfirst Make a string's first character uppercase.
ucsplit Split a string into pieces by uppercase characters.
upper Convert the given string to upper-case.
wordWrap Wrap a string to a given number of characters using a specified line break.

Str::camel

Description

public static camel (string $value)

Convert a value to camel case.

Parameters

  • (string) $value

Return Values

string


Str::clean_url

Description

public static clean_url (string $str)

Clean a URL string.

Parameters

  • (string) $str : The string to clean. Return Values

string|null

The cleaned URL.


Str::e

Description

public static e (string $str, bool $nl2br)

Clean a text string.

Parameters

  • (string) $str : The string to clean.* (bool) $nl2br : Convert newlines to
    tags. Return Values

string

The cleaned text.


Str::form_element_name

Description

public static form_element_name (string $str)

Generate a form element name from a string.

Parameters

  • (string) $str : The string to convert. Return Values

string

The form element name.


Str::fromBase64

Description

public static fromBase64 (string $string, bool $strict)

Decode the given Base64 encoded string.

Parameters

  • (string) $string
  • (bool) $strict

Return Values

string|false


Str::headline

Description

public static headline (string $string)

Convert various string formats to a capitalized headline.

Parameters

  • (string) $string : The input string. Return Values

string

The headline formatted string.


Str::kebab

Description

public static kebab (string $string)

Convert a camelCase string to kebab-case.

Parameters

  • (string) $string : The camelCase string. Return Values

string

The kebab-case string.


Str::lcfirst

Description

public static lcfirst (string $string)

Make a string's first character lowercase.

Parameters

  • (string) $string

Return Values

string


Str::length

Description

public static length (string $value, string|null $encoding)

Return the length of the given string.

Parameters

  • (string) $value
  • (string|null) $encoding

Return Values

int


Str::limit

Description

public static limit (string $value, int $limit, string $end, bool $preserveWords)

Limit the number of characters in a string.

Parameters

  • (string) $value
  • (int) $limit
  • (string) $end
  • (bool) $preserveWords

Return Values

string


Str::lower

Description

public static lower (string $value)

Convert the given string to lower-case.

Parameters

  • (string) $value

Return Values

string


Str::ltrim

Description

public static ltrim (string $value, string|null $charlist)

Remove all whitespace from the beginning of a string.

Parameters

  • (string) $value
  • (string|null) $charlist

Return Values

string


Str::p

Description

public static p (mixed $t)

Print a variable in a readable format.

Parameters

  • (mixed) $t : The variable to print. Return Values

string

The formatted variable.


Str::parse_my_url

Description

public static parse_my_url (void)

Parse the current URL into an array of segments.

Parameters

This function has no parameters.

Return Values

array

The URL segments.


Str::randomString

Description

public static randomString (int $length, bool $lowercase, bool $uppercase, bool $number)

Generate a random string.

Parameters

  • (int) $length : Length of the string to generate.* (bool) $lowercase : Include lowercase letters.* (bool) $uppercase : Include uppercase letters.* (bool) $number : Include numbers. Return Values

string

The generated random string.


Str::removePound

Description

public static removePound (string $tt)

Remove pound signs and dashes from a string.

Parameters

  • (string) $tt : The string to modify. Return Values

string

The modified string.


Str::rtrim

Description

public static rtrim (string $value, string|null $charlist)

Remove all whitespace from the end of a string.

Parameters

  • (string) $value
  • (string|null) $charlist

Return Values

string


Str::snake

Description

public static snake (string $value, string $delimiter)

Convert a string to snake case.

Parameters

  • (string) $value
  • (string) $delimiter

Return Values

string


Str::studly

Description

public static studly (string $value)

Convert a value to studly caps case.

Parameters

  • (string) $value

Return Values

string


Str::substr

Description

public static substr (string $string, int $start, int|null $length, string $encoding)

Returns the portion of the string specified by the start and length parameters.

Parameters

  • (string) $string
  • (int) $start
  • (int|null) $length
  • (string) $encoding

Return Values

string


Str::swap

Description

public static swap (array $replacements, string $string)

Swap keywords in a string according to a mapping array.

Parameters

  • (array) $replacements : An associative array of replacements.* (string) $string : The original string. Return Values

string

The string with replacements.


Str::title

Description

public static title (string $value)

Convert the given string to proper case.

Parameters

  • (string) $value

Return Values

string


Str::toBase64

Description

public static toBase64 (string $string)

Convert the given string to Base64 encoding.

Parameters

  • (string) $string

Return Values

string


Str::trim

Description

public static trim (string $value, string|null $charlist)

Remove all whitespace from both ends of a string.

Parameters

  • (string) $value
  • (string|null) $charlist

Return Values

string


Str::ucfirst

Description

public static ucfirst (string $string)

Make a string's first character uppercase.

Parameters

  • (string) $string

Return Values

string


Str::ucsplit

Description

public static ucsplit (string $string)

Split a string into pieces by uppercase characters.

Parameters

  • (string) $string

Return Values

string[]


Str::upper

Description

public static upper (string $value)

Convert the given string to upper-case.

Parameters

  • (string) $value

Return Values

string


Str::wordWrap

Description

public static wordWrap (string $text, int $characters, string $break)

Wrap a string to a given number of characters using a specified line break.

Parameters

  • (string) $text : The input string.* (int) $characters : The max number of characters per line.* (string) $break : The line break delimiter. Return Values

string

The word-wrapped string.