The Blog

Laravel

Laravel

Laravel Array Helper Functions

John Koster
John Koster
November 18, 2016

Learn about Laravel's array helper functions and how they provide additional functionality on top of PHP's built-in array functions. These functions are located within the Illuminate\Support\Arr class and treat arrays as immutable data structures. See an example of how changes made to an array are returned as a copy of the original array, with the original array remaining unchanged. Discover how Laravel's helper functions support "dot" notation when accessing items in an array, similar to JavaScript's dot notation for accessing object properties.

Laravel

Laravel Helper Function: ASCII

John Koster
John Koster
November 16, 2016

The ascii helper method in Laravel converts a UTF-8 encoded string into its ASCII equivalent. It accepts a single argument, which should be a string or something that can be cast into a string. This function is useful when communicating with other software platforms that require ASCII, or when complying with protocols like HTTP. In Laravel 5, the ascii function uses the stringy library, while previous versions of Laravel used the patchwork/utf8 package.

Laravel

Laravel String Helper Function: studly_case

John Koster
John Koster
November 16, 2016

Studly caps is a formatting style for text that involves capitalizing the first letter of each word while removing certain word separators. Laravel provides a Str::studly method to implement this formatting. Examples include transforming "my words" to "MyWords" and "my-WORDS" to "MyWORDS". Pascal case, which is similar to camel case with the first letter capitalized, can also be achieved with studly. There is also a global function studly_case available as a shortcut to Str::studly.

Laravel

Laravel Security Helper Function: e for HTML Entities

John Koster
John Koster
November 16, 2016

Learn how to use the e function in PHP to sanitize user input and prevent potential security vulnerabilities. The e function is a convenient wrapper for PHP's htmlentities function and utilizes the UTF-8 character encoding. By using the e function, you can safely display user input in the browser without the risk of executing malicious code. Discover how to implement the e function and ensure that the browser renders user input as intended.

Laravel

Laravel String Helper Function: camel

John Koster
John Koster
November 16, 2016

Learn how to use the camel helper function in Laravel's Illuminate\Support\Str class to convert strings to camel case. Discover examples of how to convert various forms of strings to camel case, and understand that the function only affects the casings of the first character. Additionally, find out about the convenient camel_case function, which is a shortcut to calling Str::camel.

Laravel

Laravel String Helper Function: contains

John Koster
John Koster
November 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

Laravel String Helper Function: ends_with

John Koster
John Koster
November 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

Laravel String Helper Function: equals

John Koster
John Koster
November 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

Laravel String Helper Function: finish

John Koster
John Koster
November 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

Laravel String Helper Function: is

John Koster
John Koster
November 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.

Latest posts

Where Things get Good: Moving on to Forte Development Phase 1

Wrapping up Forte Phase 0 with the lexer and parser now in private alpha, and kicking off Phase 1 wi...

Read more
Forte Update: Backtracking, Metadata, HTML Validation, and More

A Forte development update: the parser now supports backtracking, improvements to node metadata, ide...

Read more
Parsing HTML and Blade Attributes in Forte

Wrapping up attribute parsing in Forte's HTML parser, from simple HTML attributes to complex, edge-c...

Read more
Switch Statements and Parser Extensions in Forte

Exploring how Forte's parser extensions can be used to handle complex Blade directives like nested s...

Read more
Parsing Blade Comments in Forte

Digging into parsing Blade and HTML comments while building Forte's HTML parser for Laravel Blade.

Read more
Thoughts on HTML Elements and Blade Components in Forte

This week I’m tackling Forte's HTML parser - consolidating Blade, Flux, and Livewire components into...

Read more