PHP code example of jameslevi / string

1. Go to this page and download the library: Download jameslevi/string library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jameslevi / string example snippets




if(file_exists(__DIR__.'/vendor/autoload.php'))
{
    

// Returns true because "hello" matches one of the word inside array.
str_equals("hello", array(
  "hello",
  "world",
))

str_starts_with("hello", "h") // Returns true because hello starts with an h.

// Returns false because @email.com is not gmail.com",
  "@yahoo.com",
))

str_remove("hello world", "l") // Returns "heo word".

str_move("hello world", 1, 2) // Returns "ello wor".

str_move_left("hello world", 3) // Returns "lo world".

str_move_right("hello world", 2) // Returns "hello wor".

str_count_numeric("hello world 123") // Returns "3".

str_count_uppercase_letter("Hello World") // Returns "2".

str_count_lowercase_letter("Hello World") // Returns "8".

str_count_letter("Hello World") // Returns "10".

str_count_line("Hello World") // Returns "1".

str_count_spaces("Hello World") // Returns "1".

str_count_special_chars("Hello World!!!") // Returns "3".

str_count_words("Hello World") // Returns "2".

str_words("Hello World") 

str_contains("Hello World", "Hello") // Returns true.

str_break("Hello World", " ")

str_is_upper("hello world") // Returns false.
str_is_upper("Hello World") // Returns false.
str_is_upper("HELLO WORLD") // Returns true.

str_is_lower("hello world") // Returns true.
str_is_lower("Hello World") // Returns false.
str_is_lower("HELLO WORLD") // Returns false.

str_uppercase("hello world", 0) // Returns "Hello world".

str_lowercase("Hello World", 6) // Returns "Hello world".

str_to_camel("Hello World") // Returns "helloWorld".

str_to_snake("Hello World") // Returns "hello_world".

str_to_kebab("Hello World") // Returns "hello-world".

str_to_pascal("Hello World") // Returns "HelloWorld".

str_camel_to_snake("helloWorld") // Returns "hello_world".

str_camel_to_kebab("helloWorld") // Returns "hello-world".

str_camel_to_pascal("helloWorld") // Returns "HelloWorld".

str_snake_to_camel("hello_world") // Returns "helloWorld".

str_snake_to_kebab("hello_world") // Returns "hello-world".

str_snake_to_pascal("hello_world") // Returns "HelloWorld".

str_kebab_to_camel("hello-world") // Returns "helloWorld".

str_kebab_to_snake("hello-world") // Returns "hello_world".

str_kebab_to_pascal("hello-world") // Returns "HelloWorld".

str_pascal_to_camel("HelloWorld") // Returns "helloWorld".

str_pascal_to_snake("HelloWorld") // Returns "hello_world".

str_pascal_to_kebab("HelloWorld") // Returns "hello-world".

str_camel_to_words("helloWorld") // Returns "hello world".

str_snake_to_words("hello_world") // Returns "hello world".

str_kebab_to_words("hello-world") // Returns "hello world".

str_pascal_to_words("HelloWorld") // Returns "hello world".

str_truncate("Hello World!!!", 8) // Returns "Hello...".

str_random(10, STR_RANDOM_DEFAULT); // Return random alphanumeric characters.
str_random(10, STR_RANDOM_NUMBERS); // Return random numbers.
str_random(10, STR_RANDOM_LETTERS); // Return random letters.
str_random(10, STR_RANDOM_LETTERS_UPPERCASE); // Return random uppercase letters.
str_random(10, STR_RANDOM_LETTERS_LOWERCASE); // Return random lowercase letters.

array(2)
(
  [0] => "Hello"
  [1] => "World"
)

array(2)
(
  [0] => "Hello"
  [1] => "World"
)