Jak przekonwertować CamelCase na Camel case?

Gdybym miał:

$string = "CamelCase";

I need

"camel_case"

Czy PHP oferuje funkcję do tego celu?

Author: Mike, 2010-01-03

27 answers

Przymierz to dla rozmiaru:

$tests = array(
  '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',
);

foreach ($tests as $test => $result) {
  $output = from_camel_case($test);
  if ($output === $result) {
    echo "Pass: $test => $result\n";
  } else {
    echo "Fail: $test => $result [$output]\n";
  }
}

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

Wyjście:

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

To implementuje następujące zasady:

  1. po sekwencji zaczynającej się od małej litery muszą następować małe litery i cyfry;
  2. po sekwencji rozpoczynającej się wielką literą może następować albo:
    • jedna lub więcej wielkich liter i cyfr (po których następuje koniec łańcucha lub wielka litera, po której następuje mała litera lub cyfra, czyli początek następnego Sekwencja); lub
    • jedna lub więcej małych liter lub cyfr.
 132
Author: cletus,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2010-01-03 02:55:12

Krótsze rozwiązanie: podobne do edytora z uproszczonym wyrażeniem regularnym i naprawianiem problemu "końcówka-podkreślenie":

$output = strtolower(preg_replace('/(?<!^)[A-Z]/', '_$0', $input));

PHP Demo | Regex Demo


Zauważ, że przypadki takie jak SimpleXML zostaną przekonwertowane na simple_x_m_l przy użyciu powyższego rozwiązania. Można to również uznać za błędne użycie notacji wielbłąda (poprawne byłoby SimpleXml), a nie błąd algorytmu, ponieważ takie przypadki są zawsze niejednoznaczne - nawet przez grupowanie wielkie litery do jednego ciągu (simple_xml) taki algorytm zawsze zawiedzie w innych przypadkach, takich jak {[6] } lub słowa jednoliterowe w pobliżu skrótów, itp. Jeśli nie masz nic przeciwko (raczej rzadkim) przypadkom krawędzi i chcesz poprawnie obsługiwać SimpleXML, możesz użyć nieco bardziej złożonego rozwiązania:

$output = ltrim(strtolower(preg_replace('/[A-Z]([A-Z](?![a-z]))*/', '_$0', $input)), '_');

PHP Demo | Regex Demo

 117
Author: Jan Jakeš,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-11-25 10:13:06

Zwięzłe rozwiązanie i poradzi sobie z trudnymi przypadkami użycia:

function decamelize($string) {
    return strtolower(preg_replace(['/([a-z\d])([A-Z])/', '/([^_])([A-Z][a-z])/'], '$1_$2', $string));
}

Może obsłużyć wszystkie te przypadki:

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
hello_world => hello_world
hello__world => hello__world
_hello_world_ => _hello_world_
hello_World => hello_world
HelloWorld => hello_world
helloWorldFoo => hello_world_foo
hello-world => hello-world
myHTMLFiLe => my_html_fi_le
aBaBaB => a_ba_ba_b
BaBaBa => ba_ba_ba
libC => lib_c

Możesz przetestować tę funkcję tutaj: http://syframework.alwaysdata.net/decamelize

 27
Author: Syone,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-03-01 09:54:36

Ported from Ruby ' s String#camelize and String#decamelize.

function decamelize($word) {
  return preg_replace(
    '/(^|[a-z])([A-Z])/e', 
    'strtolower(strlen("\\1") ? "\\1_\\2" : "\\2")',
    $word 
  ); 
}

function camelize($word) { 
  return preg_replace('/(^|_)([a-z])/e', 'strtoupper("\\2")', $word); 
}

Jedną z sztuczek, których powyższe rozwiązania mogły pominąć, jest modyfikator "e", który powoduje, że preg_replace ocenia łańcuch zastępczy jako kod PHP.

 24
Author: user644783,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-03-04 13:40:41

Większość rozwiązań tutaj czuje się ciężko. Oto czego używam:

$underscored = strtolower(
    preg_replace(
        ["/([A-Z]+)/", "/_([A-Z]+)([A-Z][a-z])/"], 
        ["_$1", "_$1_$2"], 
        lcfirst($camelCase)
    )
);

" CamelCASE "jest konwertowane na"camel_case"

  • lcfirst($camelCase) obniży pierwszy znak (unika konwersji "CamelCASE" na początek z podkreśleniem)
  • [A-Z] znajduje duże litery
  • + będzie traktował każdą kolejną wielką literę jako słowo (unika konwersji "CamelCASE" na camel_C_A_S_E)
  • drugi wzór i zamiennik są dla ThoseSPECCases -> those_spec_cases zamiast those_speccases
  • strtolower([…]) zamienia wyjście na małe litery
 20
Author: buley,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-10-26 11:37:34

KomponentSymfony Serializer maCamelCaseToSnakeCaseNameConverter , który ma dwie metody normalize() i denormalize(). Można je stosować w następujący sposób:

$nameConverter = new CamelCaseToSnakeCaseNameConverter();

echo $nameConverter->normalize('camelCase');
// outputs: camel_case

echo $nameConverter->denormalize('snake_case');
// outputs: snakeCase
 19
Author: mattvick,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-06-17 12:23:06

Php nie oferuje wbudowanej funkcji dla tego afaik, ale oto, czego używam

function uncamelize($camel,$splitter="_") {
    $camel=preg_replace('/(?!^)[[:upper:]][[:lower:]]/', '$0', preg_replace('/(?!^)[[:upper:]]+/', $splitter.'$0', $camel));
    return strtolower($camel);

}

Splitter może być określony w wywołaniu funkcji, więc można go wywołać w ten sposób

$camelized="thisStringIsCamelized";
echo uncamelize($camelized,"_");
//echoes "this_string_is_camelized"
echo uncamelize($camelized,"-");
//echoes "this-string-is-camelized"
 16
Author: ekhaled,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2010-01-03 02:36:47
header('content-type: text/html; charset=utf-8');
$separated = preg_replace('%(?<!^)\p{Lu}%usD', '_$0', 'AaaaBbbbCcccDdddÁáááŐőőő');
$lower = mb_strtolower($separated, 'utf-8');
echo $lower; //aaaa_bbbb_cccc_dddd_áááá_őőőő

(przyjęte "rozwiązanie" jest epicką porażką...)

 8
Author: inf3rno,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-05-25 22:57:18

Wcale nie fantazyjne, ale proste i szybkie jak diabli:

function uncamelize($str) 
{
    $str = lcfirst($str);
    $lc = strtolower($str);
    $result = '';
    $length = strlen($str);
    for ($i = 0; $i < $length; $i++) {
        $result .= ($str[$i] == $lc[$i] ? '' : '_') . $lc[$i];
    }
    return $result;
}

echo uncamelize('HelloAWorld'); //hello_a_world
 4
Author: Edakos,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-12-16 18:23:38

Jeśli szukasz wersji PHP 5.4 i późniejszej odpowiedzi, oto kod:

function decamelize($word) {
      return $word = preg_replace_callback(
        "/(^|[a-z])([A-Z])/",
        function($m) { return strtolower(strlen($m[1]) ? "$m[1]_$m[2]" : "$m[2]"); },
        $word
    );

}
function camelize($word) {
    return $word = preg_replace_callback(
        "/(^|_)([a-z])/",
        function($m) { return strtoupper("$m[2]"); },
        $word
    );

} 
 4
Author: shacharsol,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-02-25 23:20:03

"CamelCase" do "camel_case":

function camelToSnake($camel)
{
    $snake = preg_replace('/[A-Z]/', '_$0', $camel);
    $snake = strtolower($snake);
    $snake = ltrim($snake, '_');
    return $snake;
}

Lub:

function camelToSnake($camel)
{
    $snake = preg_replace_callback('/[A-Z]/', function ($match){
        return '_' . strtolower($match[0]);
    }, $camel);
    return ltrim($snake, '_');
}
 4
Author: xiaojing,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-12-05 02:09:30

Wersja, która nie używa regex można znaleźć w Alchitect source:

decamelize($str, $glue='_')
{
    $counter  = 0;
    $uc_chars = '';
    $new_str  = array();
    $str_len  = strlen($str);

    for ($x=0; $x<$str_len; ++$x)
    {
        $ascii_val = ord($str[$x]);

        if ($ascii_val >= 65 && $ascii_val <= 90)
        {
            $uc_chars .= $str[$x];
        }
    }

    $tok = strtok($str, $uc_chars);

    while ($tok !== false)
    {
        $new_char  = chr(ord($uc_chars[$counter]) + 32);
        $new_str[] = $new_char . $tok;
        $tok       = strtok($uc_chars);

        ++$counter;
    }

    return implode($new_str, $glue);
}
 3
Author: Darrell Brogdon,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2010-01-03 03:58:20

Oto jednolinijkowy:

strtolower(preg_replace('/(?|([a-z\d])([A-Z])|([^\^])([A-Z][a-z]))/', '$1_$2', $string));
 3
Author: seelts,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-09-17 17:33:39

Danielstjules / Stringy dostarcza metodę konwersji łańcucha z camelcase na snakecase.

s('TestUCase')->underscored(); // 'test_u_case'
 3
Author: Jimmy Ko,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-11-29 12:35:27

Bezpośredni port z rails (minus ich Specjalna obsługa dla :: lub akronimów) to

function underscore($word){
    $word = preg_replace('#([A-Z\d]+)([A-Z][a-z])#','\1_\2', $word);
    $word = preg_replace('#([a-z\d])([A-Z])#', '\1_\2', $word);
    return strtolower(strtr($word, '-', '_'));
}

Znając PHP, będzie to szybsze niż ręczne parsowanie, które dzieje się w innych odpowiedziach podanych tutaj. Wadą jest to, że nie masz wyboru, co używać jako separator między słowami, ale to nie było częścią pytania.

Sprawdź również odpowiedni kod źródłowy rails

Zauważ, że jest to przeznaczone do użytku z identyfikatorami ASCII. Jeśli musisz to zrobić w przypadku znaków spoza zakresu ASCII użyj modyfikatora '/ u ' dla preg_matchi mb_strtolower.

 2
Author: pilif,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-10-23 19:43:18

Oto mój wkład w sześcioletnie pytanie z Bóg wie ile odpowiedzi...

Konwertuje wszystkie słowa w podanym ciągu znaków, które są w camelcase na snakecase. Na przykład "SuperSpecialAwesome a także fizbuzz καιΚάτιΑκόμα "zostaną przekonwertowane na"super_special_awesome a także fizz_buzz και_κάτι_ακόμα".

mb_strtolower(
    preg_replace_callback(
        '/(?<!\b|_)\p{Lu}/u',
        function ($a) {
            return "_$a[0]";
        },
        'SuperSpecialAwesome'
    )
);
 2
Author: Loupax,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-12-29 12:24:25

Laravel 5.6 zapewnia bardzo prosty sposób na to:

 /**
 * Convert a string to snake case.
 *
 * @param  string  $value
 * @param  string  $delimiter
 * @return string
 */
public static function snake($value, $delimiter = '_'): string
{
    if (!ctype_lower($value)) {
        $value = strtolower(preg_replace('/(.)(?=[A-Z])/u', '$1'.$delimiter, $value));
    }

    return $value;
}

Co robi: jeśli widzi, że w danym łańcuchu jest co najmniej jedna wielka litera, używadodatniego spojrzenia do wyszukiwania dowolnego znaku (.), po którym następuje wielka litera ((?=[A-Z])). Następnie zastępuje znaleziony znak jego wartością, a następnie separatorem _.

 2
Author: Valdrinit,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-06-27 11:27:04

Tego używam do dekamelizacji metody:

function decamelize($str, $glue='_') {
  $capitals = array();
  $replace  = array();

  foreach(str_split($str) as $index => $char) {
     if(ord($char) >= 65 && ord($char) <= 90) {
        $capitals[] = $char;
        $replace[] = ($index > 0 ? $glue : '').strtolower($char);
     }
  }

  if(sizeof($capitals)) return str_replace($capitals, $replace, $str);

  return $str;
}
 1
Author: baldrs,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-04-09 12:37:32
function camel2snake($name) {
    $str_arr = str_split($name);
    foreach ($str_arr as $k => &$v) {
        if (ord($v) >= 64 && ord($v) <= 90) { // A = 64; Z = 90
            $v = strtolower($v);
            $v = ($k != 0) ? '_'.$v : $v;
        }
    }
    return implode('', $str_arr);
}
 1
Author: Kurt Zhong,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-12-05 05:14:24

Istnieje biblioteka zapewniająca tę funkcjonalność:

SnakeCaseFormatter::run('CamelCase'); // Output: "camel_case"
 1
Author: Kolyunya,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-04-02 09:33:11

Jeśli używasz frameworka Laravel, możesz użyć tylko metody snake_case () .

 1
Author: Marek Skiba,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-11-11 16:25:48
$str = 'FooBarBaz';

return strtolower(preg_replace('~(?<=\\w)([A-Z])~', '_$1', $str)); // foo_bar_baz
 1
Author: Omar Makled,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-10-25 09:39:47

Łatwo jest używać klas filtrów Zend Word Filters :

<?php
namespace MyNamespace\Utility;

use Zend\Filter\Word\CamelCaseToUnderscore;
use Zend\Filter\Word\UnderscoreToCamelCase;

class String
{
    public function test()
    {
        $underscoredStrings = array(
            'simple_test',
            'easy',
            'html',
            'simple_xml',
            'pdf_load',
            'start_middle_last',
            'a_string',
            'some4_numbers234',
            'test123_string',
        );
        $camelCasedStrings = array(
            'simpleTest',
            'easy',
            'HTML',
            'simpleXML',
            'PDFLoad',
            'startMIDDLELast',
            'AString',
            'Some4Numbers234',
            'TEST123String',
        );
        echo PHP_EOL . '-----' . 'underscoreToCamelCase' . '-----' . PHP_EOL;
        foreach ($underscoredStrings as $rawString) {
            $filteredString = $this->underscoreToCamelCase($rawString);
            echo PHP_EOL . $rawString . ' >>> ' . $filteredString . PHP_EOL;
        }
        echo PHP_EOL . '-----' . 'camelCaseToUnderscore' . '-----' . PHP_EOL;
        foreach ($camelCasedStrings as $rawString) {
            $filteredString = $this->camelCaseToUnderscore($rawString);
            echo PHP_EOL . $rawString . ' >>> ' . $filteredString . PHP_EOL;
        }
    }

    public function camelCaseToUnderscore($input)
    {
        $camelCaseToSeparatorFilter = new CamelCaseToUnderscore();
        $result = $camelCaseToSeparatorFilter->filter($input);
        $result = strtolower($result);
        return $result;
    }

    public function underscoreToCamelCase($input)
    {
        $underscoreToCamelCaseFilter = new UnderscoreToCamelCase();
        $result = $underscoreToCamelCaseFilter->filter($input);
        return $result;
    }
}

-----underscoreToCamelCase - - - - -

Simple_test > > > SimpleTest

Easy > > Easy

Html > > > Html

Simple_xml > > > SimpleXml

Pdf_load > > > PdfLoad

Start_middle_last > > > StartMiddleLast

A_string > > > AString

Some4_numbers234 > > > Some4Numbers234

Test123_string >>> Test123String

-----camelCaseToUnderscore - - - - -

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

 0
Author: automatix,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-12-16 17:02:13

Najgorsza odpowiedź tutaj była tak bliska bycia najlepszą(użyj frameworka). Nie, po prostu spójrz na kod źródłowy. o wiele bardziej wiarygodnym podejściem(wypróbowanym i przetestowanym) byłoby sprawdzenie, jakie zastosowania mają dobrze ugruntowane ramy. Zend Framework ma kilka filtrów słów, które pasują do Twoich potrzeb. Źródło .

Oto kilka metod, które zaadaptowałem ze źródła.

function CamelCaseToSeparator($value,$separator = ' ')
{
    if (!is_scalar($value) && !is_array($value)) {
        return $value;
    }
    if (defined('PREG_BAD_UTF8_OFFSET_ERROR') && preg_match('/\pL/u', 'a') == 1) {
        $pattern     = ['#(?<=(?:\p{Lu}))(\p{Lu}\p{Ll})#', '#(?<=(?:\p{Ll}|\p{Nd}))(\p{Lu})#'];
        $replacement = [$separator . '\1', $separator . '\1'];
    } else {
        $pattern     = ['#(?<=(?:[A-Z]))([A-Z]+)([A-Z][a-z])#', '#(?<=(?:[a-z0-9]))([A-Z])#'];
        $replacement = ['\1' . $separator . '\2', $separator . '\1'];
    }
    return preg_replace($pattern, $replacement, $value);
}
function CamelCaseToUnderscore($value){
    return CamelCaseToSeparator($value,'_');
}
function CamelCaseToDash($value){
    return CamelCaseToSeparator($value,'-');
}
$string = CamelCaseToUnderscore("CamelCase");
 0
Author: TarranJones,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-11-09 09:36:52

Open source biblioteka TurboCommons zawiera metodę formatCase() ogólnego przeznaczenia wewnątrz klasy StringUtils, która pozwala konwertować łańcuch znaków na wiele popularnych formatów, takich jak CamelCase, UpperCamelCase, LowerCamelCase, snake_case, TITLE Case i wiele innych.

Https://github.com/edertone/TurboCommons

Aby go użyć, zaimportuj plik phar do swojego projektu i:

use org\turbocommons\src\main\php\utils\StringUtils;

echo StringUtils::formatCase('camelCase', StringUtils::FORMAT_SNAKE_CASE);

// will output 'camel_Case'
 0
Author: Jaume Mussons Abad,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-03-10 23:31:01

Yii2 mają inną funkcję, aby utworzyć słowo snake_case z CamelCase.

    /**
     * Converts any "CamelCased" into an "underscored_word".
     * @param string $words the word(s) to underscore
     * @return string
     */
    public static function underscore($words)
    {
        return strtolower(preg_replace('/(?<=\\w)([A-Z])/', '_\\1', $words));
    }
 0
Author: Anil Chaudhari,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-08-22 07:14:25

Jeśli możesz zacząć od:

$string = 'Camel_Case'; // underscore or any other separator...

Następnie można przekształcić do obu przypadków tylko za pomocą:

$pascal = str_replace("_", "", $string);
$snake = strtolower($string);

Lub w innych przypadkach:

$capitalized = str_replace("_", " ", $string); // Camel Case
$constant = strtoupper($string);               // CAMEL_CASE
$train = str_replace("_", "-", $snake);        // camel-case
 -1
Author: Nuno Rafael Figueiredo,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-03-28 15:40:21