Search

The blog - interstellar.

Laravel String Helper Function: contains

Nov 16, 2016

Learn how to use the contains helper method in PHP to check if a given value contains any of the specified needles. The contains method returns true if any needles are found in the haystack, otherwise it returns false. Find out how you can easily call this method using the str_contains function, a shortcut to Str::contains.
Laravel String Helper Function: ends_with

Nov 16, 2016

The endsWith helper method in Laravel is used to check if a string ends with any of the provided characters. It returns true if the string ends with any of the characters and false otherwise. This method can be used in combination with PHP's range function to check if a string ends with any alphabetical character. Additionally, there is a shortcut function ends_with that can be used instead of calling Str::endsWith directly.
Laravel String Helper Function: equals

Nov 16, 2016

The equals method in Laravel compares two strings to check if they are the same. It returns a boolean value indicating whether the strings are equal or not. This method implements a constant-time algorithm, so the time it takes to complete doesn't increase with the size of the strings. However, starting from Laravel version 5.2, it is recommended to use PHP's built-in hash_equals function instead. The equals method may leak length information through timing attacks if the input strings have different lengths. For more information on security considerations and relevant resources, please refer to the provided links.
Laravel String Helper Function: finish

Nov 16, 2016

The finish helper method is a useful tool for ensuring that a given value ends with a specified character or string. It's commonly used for constructing URIs or file paths, and can accept any string of characters as the ending. This helper function is particularly handy when combined with the slug method, allowing for easy generation of interesting results. Additionally, for convenience, there is a shortcut function called str_finish that can be used in the global namespace.
Laravel String Helper Function: is

Nov 16, 2016

The is helper method is used to determine if a value matches a specific pattern. It returns true if the value matches the pattern, and false otherwise. You can use wildcards in the pattern for flexible matching. The str_is function is a shortcut for calling the is method. It can be used globally without the need for importing the Str class.
Laravel String Helper Function: length

Nov 16, 2016

The length helper method in Laravel returns the length of a given value in PHP. It utilizes PHP's internal character encoding to calculate the length. For example, Str::length('12345') would return 5, and Str::length(str_repeat('n', 120)) would return 120. Additionally, str_repeat is a PHP function that repeats a given input a specified number of times, such as str_repeat('n', 120) resulting in a string with 120 occurrences of the character 'n'.
Laravel String Helper Function: limit

Nov 16, 2016

The limit method is a useful helper function in Laravel's Str class that ensures a provided value does not exceed a specified limit. It appends a given end sequence if the value is trimmed. This is particularly useful when displaying lengthy user-generated content to avoid issues with UI layouts. The str_limit function is a shortcut to calling Str::limit and is defined in the global namespace.
Laravel String Helper Function: lower

Nov 16, 2016

The lower helper method converts a given value to lowercase. Use the lower function by passing the desired value as an argument. For example, Str::lower('ALL LOWER CASED') will output "all lower cased".
Laravel String Helper Function: parse_callback

Nov 16, 2016

Learn how to use the parseCallback helper method in Laravel to split a string with a class name and method name. With the $default parameter, you can specify a default method if no method name is provided. The parseCallback function returns an array containing the class name and method name. Check out some examples of usage to understand how it works.
Laravel String Helper Function: quick_random

Nov 16, 2016

Learn how to use the quickRandom helper method in Laravel to generate random strings quickly. This method is similar to random, but does not rely on the OpenSSL extension. It generates strings from a pool of alpha-numeric characters. Keep in mind that quickRandom is not suitable for generating cryptographically secure strings. See examples of quickRandom output in the code snippet provided.
Laravel String Helper Function: random

Nov 16, 2016

The random helper method generates a random string of the specified length and requires the OpenSSL extension to be installed and configured. If the OpenSSL extension is not installed, a RuntimeException will be thrown. The random method removes certain characters from the generated string. Additionally, there is a shortcut function called str_random that calls Str::random.
Laravel String Helper Function: randomBytes

Nov 16, 2016

The randomBytes helper method generates a string of random bytes with the specified length. It is recommended over the random method as it produces more random results. The helper method requires the OpenSSL extension for PHP 5 and uses the openssl_random_pseudo_bytes function. In PHP 7, the random_bytes function is utilized instead. Laravel version 5.2 deprecated the randomBytes helper method in favor of PHP's random_bytes function. If OpenSSL is not installed or configured, or if the method fails to generate a random string, a RuntimeException will be thrown.
Laravel String Helper Function: singular

Nov 16, 2016

The singular helper method in Laravel is used to convert a plural word into its singular form. This method is the opposite of the plural method. It follows similar internal mechanisms as the plural method. In Laravel, you can also use the str_singular() function as a shortcut to calling Str::singular.
Laravel String Helper Function: slug

Nov 16, 2016

The slug helper method in Laravel is used to format a given title into a URI slug. It converts the title to ASCII, replaces whitespace and separators with a specified character, and trims whitespace and separators from the beginning and end of the string. The str_slug function serves as a shortcut to the Str::slug method, making it easier to use in global namespace.

Some absolutely amazing
people

The following amazing people help support this site and my open source projects ♥️
If you're interesting in supporting my work and want to show up on this list, check out my GitHub Sponsors Profile.