U( 'world') ->prepend( 'hello') // 'helloworld' You can performĬase-insensitive operations with the ignoreCase() method:ģ2 // adds the given content (one or more strings) at the beginning/end of the string The methods of all string classes are case-sensitive by default. U( 'Foo: Bar-baz.') ->snake() // 'foo_bar_baz' // other cases can be achieved by chaining methods. U( 'Foo: Bar-baz.') ->camel() // 'fooBarBaz' // changes all graphemes/code points to snake_case U( 'foo bar') ->title( true) // 'Foo Bar' // changes all graphemes/code points to camelCase U( 'foo BAR') ->upper() // 'FOO BAR' // changes all graphemes/code points to "title case" U( 'Die O\'Brian Straße') ->folded() // "die o'brian strasse" // changes all graphemes/code points to upper case this method returns a string that you can use in case-insensitive comparisons U( 'FOO Bar') ->lower() // 'foo bar' // when dealing with different languages, uppercase/lowercase is not enough // there are three cases (lower, upper, title), some characters have no case, // case is context-sensitive and locale-sensitive, etc. U( " \n\n hello \t \n\r world \n \n") ->collapseWhitespace() // 'hello world'Ģ3 // changes all graphemes/code points to lower case ![]() U( '') ->isEmpty() // true // removes all whitespace (' \n\r\t\x0C') from the start and end of the string and // replaces two or more consecutive whitespace characters with a single space (' ') character ( new UnicodeString( $word)) ->width() // 4 // if the text contains multiple lines, it returns the max width of all lines $text = "width() // 14 // only returns TRUE if the string is exactly an empty string (not even whitespace) ( new CodePointString( $word)) ->width() // 4 ( new ByteString( $word)) ->width() // 18 This method returns the total width // needed to represent the entire word $word = 'नमस्ते' ( new UnicodeString( $word)) ->length() // 4 (graphemes) // some symbols require double the width of others to represent them when using // a monospaced font (e.g. ( new CodePointString( $word)) ->length() // 6 (code points) ( new ByteString( $word)) ->length() // 18 (bytes) The same word written in English ( hello) and Hindi ( नमस्ते):Ģ8 // returns the number of graphemes, code points or bytes of the given string $word = 'नमस्ते' The following image displays the bytes, code points and grapheme clusters for EachĬode point can require one or more bytes of storage depending on the standard
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |