Use Camel Case in PHP - toolpage.org
CamelCase Converter

Use Camel Case in PHP

There is no native function in PHP to convert strings to Camel Case. To convert individual strings or texts in your PHP programs to camel case notation, you can use our large CaseConverter class, which you can find on GitHub:

PHP Case Converter
https://github.com/toolpage/php-case-converter

An example call looks like this:

<?php require_once("CaseConverter.php"); $caseConverter = new CaseConverter(); echo $caseConverter->convertToCamelCase("Camel case notation"); // CamelCaseNotation

CamelCase function for PHP

If you don't want to use our class and only need a small function, this function might help you:

function convertToCamelCase(string $value, string $encoding = null) { if ($encoding == null){ $encoding = mb_internal_encoding(); } $stripChars = "()[]{}=?!.:,-_+\"#~/"; $len = strlen( $stripChars ); for($i = 0; $len > $i; $i ++) { $value = str_replace( $stripChars [$i], " ", $value ); } $value = mb_convert_case( $value, MB_CASE_TITLE, $encoding ); $value = preg_replace( "/\s+/", "", $value ); return $value; }

For example, a corresponding usage might look like this:

echo convertToCamelCase("Camel case notation"); // CamelCaseNotation

Other Implementations