Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Try this on for size:</p> <pre><code>$tests = array( 'simpleTest' =&gt; 'simple_test', 'easy' =&gt; 'easy', 'HTML' =&gt; 'html', 'simpleXML' =&gt; 'simple_xml', 'PDFLoad' =&gt; 'pdf_load', 'startMIDDLELast' =&gt; 'start_middle_last', 'AString' =&gt; 'a_string', 'Some4Numbers234' =&gt; 'some4_numbers234', 'TEST123String' =&gt; 'test123_string', ); foreach ($tests as $test =&gt; $result) { $output = from_camel_case($test); if ($output === $result) { echo "Pass: $test =&gt; $result\n"; } else { echo "Fail: $test =&gt; $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 &amp;$match) { $match = $match == strtoupper($match) ? strtolower($match) : lcfirst($match); } return implode('_', $ret); } </code></pre> <p>Output:</p> <pre><code>Pass: simpleTest =&gt; simple_test Pass: easy =&gt; easy Pass: HTML =&gt; html Pass: simpleXML =&gt; simple_xml Pass: PDFLoad =&gt; pdf_load Pass: startMIDDLELast =&gt; start_middle_last Pass: AString =&gt; a_string Pass: Some4Numbers234 =&gt; some4_numbers234 Pass: TEST123String =&gt; test123_string </code></pre> <p>This implements the following rules:</p> <ol> <li>A sequence beginning with a lowercase letter must be followed by lowercase letters and digits;</li> <li>A sequence beginning with an uppercase letter can be followed by either: <ul> <li>one or more uppercase letters and digits (followed by either the end of the string or an uppercase letter followed by a lowercase letter or digit ie the start of the next sequence); or</li> <li>one or more lowercase letters or digits.</li> </ul></li> </ol>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload