AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |
Back to Blog
Laravel str replace1/14/2024 ![]() Laravel String Manipulation | random() method usage Laravel String Manipulation | random() method output 16- replaceArray($search, array $replace, $subject) This method generates a random string, the default length of the returned string is 16. Laravel String Manipulation | plural() method usage Laravel String Manipulation | plural() method output 15- random($length = 16) : string This method converts a given word or last word of the string to plural form. ![]() Laravel String Manipulation | words() method usage Laravel String Manipulation | words() method output 14- plural($value, $count = 2) : string This method limits the string on words just like limit() method. Laravel String Manipulation | lower() method usage Laravel String Manipulation | lower() method output 13- words($value, $words = 100, $end = '.') : string This method converts the string to a lower-case string. Laravel String Manipulation | limit() method usage Laravel String Manipulation | limit() method output 12- lower($value) : string This method limits the string at a $limit, the default value for limit is 100 characters which is excluding the $end text. Laravel String Manipulation | length() method usage Laravel String Manipulation | length() method output 11- limit($value, $limit = 100, $end = '.') : string This method uses mbstring extension's mb_strlen() function for length, for non-ascii (Unicode) strings you have to provide $encoding scheme name such as UTF-8, UTF-16 etc. Laravel String Manipulation | kebab() method usage Laravel String Manipulation | kebab() method output 10- length($value, $encoding = null) : int This method turns your string into a kebab-case string. As shown below in the example: Laravel String Manipulation | is() method usage Laravel String Manipulation | is() method output 9- kebab($value) : string This method tests $value against the $pattern which can be a string or an array of strings and returns true or false if the string contains the pattern. In other words, right-pad the string, as shown below: Laravel String Manipulation | finish() method usage Laravel String Manipulation | finish() method output 8- is($pattern, $value) : bool This method add a padding to the end of the string. Let's check the example below: Laravel String Mmanipulation | endsWith() method usage Laravel String Mmanipulation | endsWith() method output 7- finish($value, $cap) : string ![]() This method tests if $haystack ends with $needles which can be a string or an array. This is a case-sensitive method, means if it has a work 'tomorrow', it will return false for 'Tomorrow' as demonstrated below: Laravel string manipulation | contains() method usage Laravel string manipulation | contains() method output 6- endsWith($haystack, $needles) : bool This method returns boolean true or false if a string $haystack contains a string / characters $needles. It will remove any spaces and join the words as shown below: Laravel string manipulation | camel() method usage Laravel string manipulation | camel() method output 5- contains($haystack, $needles) : bool This method will return a camel-case string. This will only keep the characters before the $search characters: Laravel string manipulation | before() method usage Laravel string manipulation | before() method output Laravel string manipulation | ascii() method usage Laravel string manipulation | ascii() method output This method returns the ascii equivalent of the $value string in the $language specified. Let's test this method: Str::after() Method usageĢ- ascii($value, $language = 'en') : string This method chops off all the characters including $search from the start in the $subject and returns the rest of the string. ![]() Here's the list of all the methods used, you can jump right to your desired method from here: For this example I will be using 'Lorem Ipsm. Let's explore what methods it contains and how we can use them. The Laravel string helpers is powered by Illuminate\Support\Str class. Laravel already provides powerfull helpers for string manipulations, but I was wondering what's behind these convinient helpers.
0 Comments
Read More
Leave a Reply. |