Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //title case + trim
- $string = " teszt cím ";
- $native = ucwords(trim($string));
- $fluent = (string)Str::of($string)
- ->trim()
- ->title();
- echo $fluent; //Teszt Cím
- //title case + replace + split
- $string = "egy kettő három";
- $native = explode(";", str_replace(" ", ";", ucwords($string)));
- $fluent = Str::of($string)
- ->title()
- ->replace(' ', ';')
- ->explode(';');
- var_dump($fluent); //Collection of ["Egy", "Kettő", "Három"]
- var_dump($fluent->toArray()); //["Egy", "Kettő", "Három"]
- //prefix
- $string = "world";
- $native = ucwords("hello " . $string);
- $fluent = (string)Str::of($string)
- ->start("hello ")
- ->title();
- echo $fluent; //Hello World
- //cut prefix + split
- $string = "N#5642-5565-5421";
- $native = explode('-', mb_substr($string, 2));
- $fluent = Str::of($string)
- ->after("N#")
- ->explode("-");
- var_dump($fluent); //Collection of [5642, 5565, 5421]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement