AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |
Back to Blog
Php string contains unacceptable value12/28/2023 String( 'Charles')-> possessive() // Charles' segment /** * Get a segment from a string based on a delimiter. * * \Spatie\String\String */ public function possessive()Įxample: string( 'Bob')-> possessive() // Bob's possessive /** * Get the possessive version of a string. This is identical to the suffix-function. * * $string * \Spatie\String\String */ public function suffix( $string)Įxample: string( 'hello')-> suffix( ' world') // hello world concat * * $string * \Spatie\String\String */ public function prefix( $string)Įxample: string( 'world')-> prefix( 'hello ') //hello world suffix /** * Suffix a string. String( $sentence)-> replaceLast( 'good', 'bad') // A good thing is not a bad thing. * * $search * $replace * \Spatie\String\String */ public function replaceLast( $search, $replace) replaceLast /** * Replace the last occurrence of a string. String( $sentence)-> replaceFirst( 'good', 'bad') // A bad thing is not a good thing. * * $search * $replace * \Spatie\String\String */ public function replaceFirst( $search, $replace)Įxample: $sentence = 'A good thing is not a good thing.' replaceFirst /** * Replace the first occurrence of a string. String( $longText)-> tease( 10) // Now that. Do you believe that shit? It actually says that in the little book that comes with it: the most popular gun in American crime.' This gun is advertised as the most popular gun in American crime. * * int $length * string $moreTextIndicator * \Spatie\String\String */ public function tease( $length = 200, $moreTextIndicator = '.')Įxample: $longText = 'Now that there is the Tec-9, a crappy spray gun from South Miami. The end * of the string is always a full word concatinated with the * specified moreTextIndicator. If the string is then still * longer than the specified $length it will be shortened. It will clean it by trimming * it, remove all double spaces and html. * * \Spatie\String\String */ public function toLower()Įxample: string( 'STRING')-> toLower() // string tease /** * Shortens a string in a pretty way. * * \Spatie\String\String */ public function toUpper()Įxample: string( 'string')-> toUpper() // STRING toLower /** * Convert the string to lowercase. * * $start * $end * \Spatie\String\String */ public function between( $start, $end)Įxample: string( 'StartMiddleEnd')-> between( 'Start', 'End')-> toUpper() // MIDDLE toUpper /** * Convert the string to uppercase. echo string( 'hello')-> toUpper() //outputs "E" $string = string( 'gray') Įcho $string-> toUpper() //outputs "GREY" Provided methods between /** * Get the string between the given start and end. You can also use offsets to manipulate a string. string( 'StartMiddleEnd')-> between( 'Start', 'End')-> toLower(). Of course you can keep concatenate the output with the. string( 'myFirstString') įrom then on you can chain methods like there's no tomorrow: echo string( 'StartMiddleEnd')-> between( 'Start', 'End')-> toUpper() // outputs "MIDDLE" This can be done with the string-function. You can install this package via composer: composer require spatie/string Usageįirst you must wrap a native string in a String-object. We publish all received postcards on our virtual postcard wall. You'll find our address on our contact page. We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You can support us by buying one of our paid products. We invest a lot of resources into creating best in class open source packages. You'll find an overview of all our open source projects on our website. Spatie is a webdesign agency in Antwerp, Belgium. This package provides a handy way to work with strings in php.
0 Comments
Read More
Leave a Reply. |