php function to convert string to camelcase

Solutions on MaxInterview for php function to convert string to camelcase by the best coders in the world

showing results for - "php function to convert string to camelcase"
Mathys
27 Aug 2019
1public static function camelCase($str, array $noStrip = [])
2{
3        // non-alpha and non-numeric characters become spaces
4        $str = preg_replace('/[^a-z0-9' . implode("", $noStrip) . ']+/i', ' ', $str);
5        $str = trim($str);
6        // uppercase the first character of each word
7        $str = ucwords($str);
8        $str = str_replace(" ", "", $str);
9        $str = lcfirst($str);
10
11        return $str;
12}
Mariangel
30 Nov 2019
1echo ucwords("hello world");
2
Luca
29 Aug 2019
1function from_camel_case($input) {
2  $pattern = '!([A-Z][A-Z0-9]*(?=$|[A-Z][a-z0-9])|[A-Za-z][a-z0-9]+)!';
3  preg_match_all($pattern, $input, $matches);
4  $ret = $matches[0];
5  foreach ($ret as &$match) {
6    $match = $match == strtoupper($match) ?
7      	strtolower($match) :
8    	lcfirst($match);
9  }
10  return implode('_', $ret);
11}
12
13// Tests:
14foreach ([
15  'simpleTest' => 'simple_test',
16  'easy' => 'easy',
17  'HTML' => 'html',
18  'simpleXML' => 'simple_xml',
19  'PDFLoad' => 'pdf_load',
20  'startMIDDLELast' => 'start_middle_last',
21  'AString' => 'a_string',
22  'Some4Numbers234' => 'some4_numbers234',
23  'TEST123String' => 'test123_string',
24] as $test => $result) {
25  $output = from_camel_case($test);
26  if ($output === $result) {
27    echo "Pass: $test => $result\n";
28  } else {
29    echo "Fail: $test => $result [$output]\n";
30  }
31}
32/*
33Pass: simpleTest => simple_test
34Pass: easy => easy
35Pass: HTML => html
36Pass: simpleXML => simple_xml
37Pass: PDFLoad => pdf_load
38Pass: startMIDDLELast => start_middle_last
39Pass: AString => a_string
40Pass: Some4Numbers234 => some4_numbers234
41Pass: TEST123String => test123_string
42*/
queries leading to this page
php add space between camelcase words phpphp camelcase to pascalcasephp camelcase methodscamel case replace phpphp regex snake casesnake case to camelcase phpphp camelcase stringphp camelcase or snake casephp get first letter of each wordphp convert dash separated words to pascal casepascalcase to camelcase phpphp convert underscore to camelcasestring camelcase in phpphp snake to camel casephp camelcase functionphp camelcase to underscoreconverting a string into camel case phptitle format string phpphp code sniffer camelcasecamel to snake case phpchange string to camel case phpphp snake casephp camel case to snake casephp string is camel case snake casephp transform camelcase to snake casephp make snake caseget only first letter of each word in phpphp object to camelcasephp to snake caseto snake case phpcamel case variable in phpsnake case or camelcase phpphp snake case or camelcasemodify variable names from camelcase to snake case phpcamel case or snake case is using phpphp string camelcasechange camel to phpconvert string to camel case symfonyphp naming convention camelcasefunction camelize 28 24str 29 phpphp convert to camel casephp replace underscore with camel casephp string to snakephp string to pascal casephp uses camelcasephp convert to snakecase to title using regexchange uppercase words to camelcase phpphp spaces to camel casingconvert underscore to camelcase phpphp camel caselaravel convert sentence to camelcasehow to convert uppercase string to camelcase in phpconvert array keys from camelcase to snake case in phpput string to snake case phpphp string to upper camel casecamel case string php convert to camelcase phpphp variable camelcase or snakehow to change the case to camel case in phpsnake case function in phpuppercase to camelcase phpphp underscore to camelcasevariable camelcase phpphp camel case tophp change snake case to camel casephp string to camel casecamel case php methodto camel case phpphp add space between camelcase wordssnakecase camelcase phpconvert to camelcase in phpuppercase to camelcase in php php camelcamel casing in phpphp string is camel casecamelcase in phpcamelcase to title case phpcamelcase do you uppercase abbreviations phpphp separate camelcasesnake case to camel case phpphp to camelcasephp uppercase wordsspeate camelcase string phppascal case phpchange a snake case to camelcase phpphp snake to camelcaseconvert camelcase to string php php create snake casestr camel phppropercase to snake case phpphp convert to camelcaselaravel convert sentence to pascalphp array keys to camelcasestring to snake case phpphp string underscore into camelcaseconvert snake to camel case phpconvert text to camel case php onlineconvert string to camelcase in phppascal case to snake case phpphp convert snake case to camel casephp string to snake casecamel case string in phpphp transform string to snake casecamel case to snake case phpconvert camel case phpstring to camel case in phpphp convert title case to snake casestring to pascal case phpphp format from snake case to camelcasestring to camel phpcamel case converter phpcamel case to normal string phpphp regex convert camelcase to snake casephp camelcae to snakecasephp convert camel case to snake casephp all caps wordsphp convert words with spaces to camelcaseconvert snake case to ucfirstphp convert array keys to camelcasephp transform underscores to camelcasephp 2b camel case to snake casephp to snake case stringphp string underscore to camelcaseis php variable camelcasephp convert snake case to pasalphp convert dash to captial underscorecamel case to lower case underscore phpsnakecase in phpphp function to convert string to camelcasephp camelcase vs snake casecamel casing phpphp format code base to camelcasephp class camelcaseconvert camel case to snake case in phphow to camelcase word in phpphp camelcase to snake casesnake case in phpphp snake case stringcamelcase to words phpstring to camlecase phpphp convert snake case to camelcasephp variable underscore to camelcase converttocamelcase in phpchange a camelcase to snake case phpphp what is snakecasephp 3a string to snake casephp convert string snake case to camel casephp camelcase variablesphp make the string camelcasecamel case php examplephp variable snake casephp str to camelcasestring to camelcase php lowercaseevery array item will be first character uppercase phpphp camel case stringcamelcase string php functioncamel case in phpcamelcase phpphp snake case str intphp captial casephp code sniffer snake case to camelcasephp convert string snakecase to camel casephp snakecasecamel case phpconvert string to snack case in phpphp variable camelcasereplace to camel case phpconvert snakel case to title case phpcheck if string is camel case or snake case phpwhy php use snake casecamel case with phpsnake case phpsnake case to uppercase phpphp snake case to camel casecapitalize each word in phphow to name variable in php camelcasesnake case phpphp capitalcaseany string to camelcase in laravelphp snake case to camelcasephp string camel casecamel case to snake case in phpget camelcase phpcamel casing example in phpsnake to camel case phpphp convert to snake caseconvert into camel case phpformat text to camel case phpstring dash to camelcase phphow to convert str lower to camelcase phpphp camelcase patternphp is camelcaseconvert string to snake case phpphp camelcasephp convert string to camelcasechange a camelcase to snake cas phpphp cucfirst for each wordsnake no camel case phpphp string to camelcaseconvert camel case to normal phpsnake case and camelcase php inconsistencyphp camel format a stringphp string manipulation camelcasedoes php use camelcase 3fphp camelcase to snakephp convert string to snake caseconvert pascal case string to snake case phpphp snake case to title casephp camel case typesphp convert camel case to snake caqephp convert string from kebab to snakeucwords 28 29 in laravel collection for uppercasephp change camelcase to underscoreconvert snake case to camel case phpstr camelcase phpphp to camelcase stringphp camel case or snake casecamelcase phpconvert camel case to snakecase phpstring to camelcase phpphp convert camelcase to snakecase arrayhow to camel case a string in phpconvert string to camel case phpconvert string to camelcase phpphp camel case to full camel casephp format code to camelcaestyle properties php camelcasephpstorm snake case to camelcaseconvert underscore notation to camel case phptext to snake case phpphp convert array keys from snake to camelcasecamelcase to snake case phpphp camel caseconvert names to camel case in phpphp function to convert string to camelcase