Search
 
SCRIPT & CODE EXAMPLE
 

PHP

php convert words with spaces to camelcase

public static function camelCase($str, array $noStrip = [])
{
        // non-alpha and non-numeric characters become spaces
        $str = preg_replace('/[^a-z0-9' . implode("", $noStrip) . ']+/i', ' ', $str);
        $str = trim($str);
        // uppercase the first character of each word
        $str = ucwords($str);
        $str = str_replace(" ", "", $str);
        $str = lcfirst($str);

        return $str;
}
Comment

php function to convert string to camelcase

echo ucwords("hello world");
Comment

php string underscore into camelcase

function dashesToCamelCase($string, $capitalizeFirstCharacter = false) 
{

    $str = str_replace(' ', '', ucwords(str_replace('-', ' ', $string)));

    if (!$capitalizeFirstCharacter) {
        $str[0] = strtolower($str[0]);
    }

    return $str;
}

echo dashesToCamelCase('this-is-a-string');
Comment

php camelcase to snake case

function from_camel_case($input) {
  $pattern = '!([A-Z][A-Z0-9]*(?=$|[A-Z][a-z0-9])|[A-Za-z][a-z0-9]+)!';
  preg_match_all($pattern, $input, $matches);
  $ret = $matches[0];
  foreach ($ret as &$match) {
    $match = $match == strtoupper($match) ?
      	strtolower($match) :
    	lcfirst($match);
  }
  return implode('_', $ret);
}

// Tests:
foreach ([
  'simpleTest' => 'simple_test',
  'easy' => 'easy',
  'HTML' => 'html',
  'simpleXML' => 'simple_xml',
  'PDFLoad' => 'pdf_load',
  'startMIDDLELast' => 'start_middle_last',
  'AString' => 'a_string',
  'Some4Numbers234' => 'some4_numbers234',
  'TEST123String' => 'test123_string',
] as $test => $result) {
  $output = from_camel_case($test);
  if ($output === $result) {
    echo "Pass: $test => $result
";
  } else {
    echo "Fail: $test => $result [$output]
";
  }
}
/*
Pass: simpleTest => simple_test
Pass: easy => easy
Pass: HTML => html
Pass: simpleXML => simple_xml
Pass: PDFLoad => pdf_load
Pass: startMIDDLELast => start_middle_last
Pass: AString => a_string
Pass: Some4Numbers234 => some4_numbers234
Pass: TEST123String => test123_string
*/
Comment

PREVIOUS NEXT
Code Example
Php :: php support block-level scope 
Php :: fore install debian 10 php 7.3 
Php :: php get timezone 
Php :: add new column to existing table laravel 
Php :: how to get value of textarea in php 
Php :: install php linux nginx command line 
Php :: laravel delete file from storage 
Php :: Check if session exists or not in laravel 
Php :: new line php 
Php :: carbon to mysql datetime 
Php :: laravel include files 
Php :: htmlspecialchars() expects parameter 1 to be string 
Php :: how to reverse fetch assoc in php 
Php :: laravel migration change column length 
Php :: Laravel Validation check array size min and max 
Php :: composer larave install version 
Php :: convert a php array into a javascript array 
Php :: array_search 
Php :: php string only letters 
Php :: get last id in laravel 
Php :: print last sql query laravel 
Php :: php check for empty string 
Php :: add custom user meta and display it in user page 
Php :: pdo bindparam string 
Php :: php date is before 
Php :: undefined method JeroenNotenLaravelAdminLteHelpersMenuItemHelper::isSearchBar() 
Php :: php date modify plus 1 day 
Php :: count number of rows laravel controller 
Php :: update onlu one column laravel 
Php :: php json_decode without quotes 
ADD CONTENT
Topic
Content
Source link
Name
1+6 =