Yii2 has a camel2words method:

 public static function camel2words($name, $ucwords = true) { $label = trim(strtolower(str_replace([ '-', '_', '.', ], ' ', preg_replace('/(?<![AZ])[AZ]/', ' \0', $name)))); return $ucwords ? ucwords($label) : $label; } 

Why is there a replacement for a пробел + экранированный ноль , why not just a пробел ?

    1 answer 1

    Emae, here I reworked ...

    A shielded zero in this case is a reference to a mask:

    replacement may contain links like \\ n, or (starting with PHP 4.0.4) $ n, with the latter option being preferred. Each such link will be replaced by a substring corresponding to the nth submask. n can take values ​​from 0 to 99, and the link \\ 0 (or $ 0) corresponds to the occurrence of the entire template. Submasks are numbered from left to right, starting from one. To use the backslash, it must be duplicated (PHP string "\\\\").

    http://php.net/manual/ru/function.preg-replace.php

    UPDATE

    When inserting a quotation with PHP.Net, it was published not quite accurately: backslashes were “eaten”. This was noticed in the comments to the answer. Now everything is corrected - the quotation is exact ... Nevertheless, as I noted, both options work (that is, \0 and \\0 ):

     $str = 'AaaBbbCcc'; echo preg_replace('/(?<![AZ])[AZ]/', ' ', $str); // aa bb cc echo "\n"; echo preg_replace('/(?<![AZ])[AZ]/', ' \0', $str); // Aaa Bbb Ccc echo "\n"; echo preg_replace('/(?<![AZ])[AZ]/', ' \\0', $str); // Aaa Bbb Ccc 

    https://repl.it/Cjmh

    Why, I don’t know, I think this is a separate issue.

    • one
      Um .. But it will be correct \\0 , and not \0 ? - Qwertiy
    • @Qwertiy, .. to be honest, I didn't even notice (I fall asleep already) ... But, nevertheless, both options work: repl.it/CjgA . - Roman Grinyov
    • @Qwertiy, hmm, .. that's all right after all: Для использования обратного слеша, его необходимо продублировать (строка PHP "\\") is about using a backslash in the replacement string, and not about a backdoor ... - Roman Grinyov
    • one
      In the documentation for your link, the slash is doubled: \\n and \\\\ . Which is logical, since the argument is a string. Or there is a very magic parser ... - Qwertiy