PHP code example of elphis / string-helpers

1. Go to this page and download the library: Download elphis/string-helpers 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/ */

    

elphis / string-helpers example snippets


    Eg: 
    $fullName   = 'John Joseph Doe';
    $fatherName = 'Joseph';
    str_contains($fullName, $fatherName); // *true*
    $fatherName = 'joseph';
    str_contains($fullName, $fatherName); // *false*
    str_contains($fullName, $fatherName, true); // *true*

    Eg: 
    $string1 = 'In the bleak mid-winter';
    $string2 = 'In the bleak mid-winter';
    str_equals($string1, $string2); // *true*
    $string2 = 'In the bleak MID-WINTER';
    str_equals($string1, $string2); // *false*
    str_equals($string1, $string2, true); // *true*

    Eg:
    $fullName  = 'John Joseph Doe';
    $firstName = 'John';
    str_starts_with($fullName, $firstName); // *true*
    $firstName = 'john';
    str_starts_with($fullName, $firstName); // *false*
    str_starts_with($fullName, $firstName, true); // *true*
    $firstName = 'joseph';
    str_starts_with($fullName, $firstName); // *false*
    str_starts_with($fullName, $firstName, true); // *false*

    Eg:
    $fullName = 'John Joseph Doe';
    $lastName = 'Doe';
    str_ends_with($fullName, $lastName); // *true*
    $lastName = 'doe';
    str_ends_with($fullName, $lastName); // *false*
    str_ends_with($fullName, $lastName, true); // *true*
    $lastName = 'joseph';
    str_ends_with($fullName, $lastName); // *false*
    str_ends_with($fullName, $lastName, true); // *false*

    Eg:
    $title = '^&%This*&(*is)(^%^#@_=0it.';
    str_strip_special_chars($title); // *Thisis0it*
    str_strip_special_chars($title, '-'); // *---This----is---------0it-*