PHP code example of parables / php-utils

1. Go to this page and download the library: Download parables/php-utils 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/ */

    

parables / php-utils example snippets


// StringUtils

normalize_whitespace(...$args)
capitalize(...$args)
instance_or_default(...$args)
slugify(...$args)
words(...$args)
is_all_upper_case(...$args)
pascal_case(...$args)
camel_case(...$args)
snake_case(...$args)
kebab_case(...$args)
excel_date_to_php_date(...$args)
array_flatten(...$args)
array_keys_transform(...$args)
array_unique_value(...$args)
is_url(...$args)
is_valid_url(...$args)

$str = "  This string \n has \t extra  \v   spaces .   ";
$normalizedStr = Utils::normalizeWhitespace($str);
// $normalizedStr = "This string has extra spaces .";

$str = "this SENTENCE needs CAPITALIZATION!";
$capitalizedStr = Utils::capitalize($str);
// $capitalizedStr = "This Sentence Needs Capitalization";

$str = "My Awesome Product Name!";
$slug = Utils::slugify($str);
// $slug = "my-awesome-product-name";

$slugWithUppercase = Utils::slugify($str, false);
// $slugWithUppercase = "My-Awesome-Product-Name";

$str = "This is a sentence with multiple words.";
$words = Utils::words($str);
// $words = ["This", "Is", "A", "Sentence", "With", "Multiple", "Words"]; 

$str = "ALL UPPERCASE";
$isAllUpper = Utils::isAllUpperCase($str); // true

$str = "Not All Uppercase";
$isAllUpper = Utils::isAllUpperCase($str); // false

$str = "this is a string";
$pascalCase = Utils::pascalCase($str);
// $pascalCase = "ThisIsString";

$str = "This is a string";
$camelCase = Utils::camelCase($str);
// $camelCase = "thisIsAString";

$str = "This is a string";
$snakeCase = Utils::snakeCase($str);
// $snakeCase = "this_is_a_string";

$str = "This is a string";
$kebabCase = Utils::kebabCase($str);
// $kebabCase = "this-is-a-string";

$url = "https://www.example.com";
$isUrlValid = Utils::isUrl($url); // true

$url = "invalid-url";
$isUrlValid = Utils::isUrl($url); // false

$url = "https://www.example.com";
$isValidUrl = Utils::isValidUrl($url); // true

$url = "invalid-url";
$isValidUrl = Utils::isValidUrl($url); // false