title: Str meta:

  • name: description content: Str string helper
  • name: keywords content: swoole|swoole extension|swoole framework|Easyswoole|Component Library|Miscellaneous Tools|Str

Str

Use

Str string helper

Core Object Class

To implement this component function you need to load the core class:

  1. EasySwoole\Utility\Str

Core Object Method

Contains

Check if another string is included in the string

  • mixed $haystack checked string
  • mixed $needles need to contain the string
  • mixed $strict is case sensitive
  1. Static function contains($haystack, $needles, $strict = true)

::: tip Example :::

  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: root
  5. * Date: 19-1-9
  6. * Time: 10:10
  7. */
  8. require './vendor/autoload.php';
  9. var_dump(\EasySwoole\Utility\Str::contains('hello, easyswoole', 'Swoole', false));
  10. /**
  11. * Output results:
  12. * bool(true)
  13. */

startsWith

Check if the string starts with a string

  • mixed $haystack checked string
  • mixed $needles need to contain the string
  • mixed $strict is case sensitive
  1. static function startsWith($haystack, $needles, $strict = true)

:::tip Example :::

  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: root
  5. * Date: 19-1-9
  6. * Time: 10:10
  7. */
  8. require './vendor/autoload.php';
  9. var_dump(\EasySwoole\Utility\Str::startsWith('hello, easyswoole', 'Hello', false));
  10. /**
  11. * Output results:
  12. * bool(true)
  13. */

endsWith

Check if the string ends with a string

  • mixed $haystack checked string
  • mixed $needles need to contain the string
  • mixed $strict is case sensitive
  1. static function endsWith($haystack, $needles, $strict = true)

:::tip

Example

:::

  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: root
  5. * Date: 19-1-9
  6. * Time: 10:10
  7. */
  8. require './vendor/autoload.php';
  9. var_dump(\EasySwoole\Utility\Str::endsWith('hello, easyswoole', 'Swoole', false));
  10. /**
  11. * Output results:
  12. * bool(true)
  13. */

snake

Hump downline

  • mixed $value pending string
  • mixed $delimiter separator
  1. static function snake($value, $delimiter = '_')

:::tip

Example

:::

  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: root
  5. * Date: 19-1-9
  6. * Time: 10:10
  7. */
  8. require './vendor/autoload.php';
  9. var_dump(\EasySwoole\Utility\Str::snake('EasySwoole'));
  10. /**
  11. * Output results:
  12. * string(11) "easy_swoole"
  13. */

camel

Underline to hump (lower initial)

  • mixed $value pending string
  1. static function camel($value)

:::tip

Example

:::

  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: root
  5. * Date: 19-1-9
  6. * Time: 10:10
  7. */
  8. require './vendor/autoload.php';
  9. var_dump(\EasySwoole\Utility\Str::camel('easy_swoole'));
  10. /**
  11. * Output results:
  12. * string(10) "easySwoole"
  13. */

studly

Underline to hump (initial capitalization)

  • mixed $value pending string
  1. static function studly($value)

:::tip

Example

:::

  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: root
  5. * Date: 19-1-9
  6. * Time: 10:10
  7. */
  8. require './vendor/autoload.php';
  9. var_dump(\EasySwoole\Utility\Str::studly('easy_swoole'));
  10. /**
  11. * Output results:
  12. * string(10) "EasySwoole"
  13. */