Str is useful for manipulating string data, you can instantiate it by calling the namespace.
use Str;
Transliterate a UTF-8 value to ASCII:
echo Str::ascii("café äëïöü");
Output:
cafe aeiou
Convert a value to camel case:
echo Str::camel("hello world!");
Output:
helloWorld!
Determine if a given string contains a given substring, will return a bool:
echo Str::contains("Hello World!", "World");
Output:
1
Determine if a given string starts with a given substring, will return a bool:
echo Str::startsWith("Hello World!", "H");
Output:
1
Determine if a given string ends with a given substring, will return a bool:
echo Str::endsWith("Hello World!", "!");
Output:
1
Cap a string with a single instance of a given value:
echo Str::finish("Hello World!", "111");
Output:
Hello World!111
Cap a string with a single instance of a given value, will return a bool:
echo Str::is("Hello World!", "Hello World!");
Output:
1
Return the length of the given string:
echo Str::length("Hello World!");
Output:
12
Limit the number of characters in a string:
echo Str::limit("Hello World!", 5, "[...]");
Output:
Hello[...]
Convert the given string to lower-case:
echo Str::lower("Hello World!");
Output:
hello world!
Convert the given string to upper-case:
echo Str::upper("Hello World!");
Output:
HELLO WORLD!
Convert the given string to title case:
echo Str::title("hello world!");
Output:
Hello World!
Convert the given string to snake case:
echo Str::snake("Hello World!");
Output:
hello_world!
Convert the given string to studly case:
echo Str::studly("Hello World!");
Output:
HelloWorld!
Make a string's first character uppercase:
echo Str::ucfirst("hello world!");
Output:
Hello world!
Limit the number of words in a string:
echo Str::words("Nova Framework is a simple but powerful MVC PHP Framework for building web applications.", 10, "[...]");
Output:
Nova Framework is a simple but powerful MVC PHP Framework
Get the plural form of an English word:
echo Str::plural("World");
Output:
Worlds
Get the singular form of an English word:
echo Str::singular("Worlds");
Output:
World
Generate a more truly "random" bytes:
echo Str::randomBytes(16);
Output:
��3!��J�.wLZS*��
OpenSSL must be enabled.
Generate a "random" alpha-numeric string.
Should not be considered sufficient for cryptography, etc:
echo Str::quickRandom(16);
Output:
lVsrlIVt4hdUf8Nn
Compares two strings using a constant-time algorithm, will return a bool:
echo Str::equals("Nova Framework", "Nova Framework");
Output:
1
Generate a URL friendly "slug" from a given string:
echo Str::slug("Nova Framework", "-");
Output:
nova-framework
Returns the portion of string specified by the start and length parameters:
echo Str::substr("Nova Framework", 0, 4);
Output:
Nova