Oihana PHP

camel.php

Table of Contents

Functions

camel()  : string
Converts a string to camelCase format.

Functions

camel()

Converts a string to camelCase format.

camel(string|null $source[, array<string|int, mixed> $separators = ["_", "-", "/"] ]) : string

This function transforms the input string by replacing specified separator characters with spaces, capitalizing each word, removing spaces, and then lowercasing the first character.

Parameters
$source : string|null

The input string to convert to camelCase. If null or empty, returns an empty string.

$separators : array<string|int, mixed> = ["_", "-", "/"]

An array of separator characters to be replaced by spaces before conversion. Defaults to ["_", "-", "/"].

Tags
example
echo camel('hello_world');        // Outputs: helloWorld
echo camel('foo-bar_baz');        // Outputs: fooBarBaz
echo camel('user/name');          // Outputs: userName
echo camel('alreadyCamelCase');   // Outputs: alreadyCamelCase
echo camel(null);                 // Outputs: (empty string)
author

Marc Alcaraz (ekameleon)

since
1.0.0
Return values
string

The camelCase representation of the input string.


        
On this page

Search results