Oihana PHP

snake.php

Table of Contents

Functions

snake()  : string
Converts a string to snake_case (or a custom delimiter).

Functions

snake()

Converts a string to snake_case (or a custom delimiter).

snake(string|null $source[, string $delimiter = '_' ]) : string

This function transforms camelCase, PascalCase, and space-separated words into snake case or any delimiter specified.

It uses an internal cache (via SnakeCache) to optimize repeated calls with the same input. The cache can be flushed by calling SnakeCache::flush().

Parameters
$source : string|null

The input string to convert.

$delimiter : string = '_'

The delimiter to use (default is underscore '_').

Tags
example
echo snake("helloWorld");     // Outputs: "hello_world"
echo snake("HelloWorld");     // Outputs: "hello_world"
echo snake("Hello World");    // Outputs: "hello_world"
echo snake("helloWorld", "-"); // Outputs: "hello-world"

Clear the internal cache if needed

use oihana\core\strings\helpers\SnakeCache;
SnakeCache::flush();
author

Marc Alcaraz (ekameleon)

since
1.0.0
Return values
string

The converted snake_case (or custom delimiter) string.


        
On this page

Search results