Skip to content

Instantly share code, notes, and snippets.

@tidusvn05
Last active September 17, 2022 11:59
Show Gist options
  • Save tidusvn05/449444ca7c22c19bf3b54434bd7ef5ab to your computer and use it in GitHub Desktop.
Save tidusvn05/449444ca7c22c19bf3b54434bd7ef5ab to your computer and use it in GitHub Desktop.

Revisions

  1. tidusvn05 revised this gist Sep 17, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion stringInvertCase.php
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,7 @@
    * Uppercase to lowercase and lowercase to uppercase(ASCII string only).
    *
    * @param string $value
    * @return string
    :x * @return string
    */
    function invertCase($value)
    {
  2. tidusvn05 created this gist Sep 17, 2022.
    15 changes: 15 additions & 0 deletions stringInvertCase.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    <?php

    /**
    * Uppercase to lowercase and lowercase to uppercase(ASCII string only).
    *
    * @param string $value
    * @return string
    */
    function invertCase($value)
    {
    return strtolower($value) ^ strtoupper($value) ^ $value;
    }

    // echo invertCase("Invert My CASE");
    // => iNVERT mY case
    22 changes: 22 additions & 0 deletions stringIsEmpty.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    <?php

    /**
    * Right trim string.
    *
    * @param string $value
    * @param bool $fullsize
    * @return string
    */
    // function rtrim($value, $fullsize = true)
    // {
    // if ($fullsize) {
    // $value = preg_replace('/[\s]+$/u', '', $value);
    // }

    // return $value;
    // }


    echo 'aaaa ';
    echo rtrim('aaaa ');
    echo rtrim('aaaa ');
    22 changes: 22 additions & 0 deletions stringStudlyCase.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    <?php

    /**
    * Convert a value to studly caps case.
    *
    *
    * @param string $value
    * @return string StudlyCaseString
    */
    function studlyCase($value)
    {
    $words = explode(' ', str_replace(['-', '_'], ' ', $value));

    $studlyWords = array_map(function ($word) {
    return ucfirst($word);
    }, $words);

    return implode($studlyWords);
    }

    // echo studlyCase("studly Case string");
    // => StudlyCaseString