src/Forms/FormField.php
public static function name_to_label($fieldName)
    {
        // Handle dot delimiters
        if (strpos($fieldName, '.') !== false) {
            $parts = explode('.', $fieldName);
            // Ensure that any letter following a dot is uppercased, so that the regex below can break it up
            // into words
            $label = implode(array_map('ucfirst', $parts));
        } else {
            $label = $fieldName;
        }

        // Replace any capital letter that is followed by a lowercase letter with a space, the lowercased
        // version of itself then the remaining lowercase letters.
        $labelWithSpaces = preg_replace_callback('/([A-Z])([a-z]+)/', function ($matches) {
            return ' ' . strtolower($matches[1]) . $matches[2];
        }, $label);

        // Add a space before any capital letter block that is at the end of the string
        $labelWithSpaces = preg_replace('/([a-z])([A-Z]+)$/', '$1 $2', $labelWithSpaces);

        // The first letter should be uppercase
        return ucfirst(trim($labelWithSpaces));
    }
public static function name_to_label($fieldName)
    {
        // Handle dot delimiters
        if (strpos($fieldName, '.') !== false) {
            $parts = explode('.', $fieldName);
            // Ensure that any letter following a dot is uppercased, so that the regex below can break it up
            // into words
            $label = implode(array_map('ucfirst', $parts));
        } else {
            $label = $fieldName;
        }

        // Replace any capital letter that is followed by a lowercase letter with a space, the lowercased
        // version of itself then the remaining lowercase letters.
        $labelWithSpaces = preg_replace_callback('/([A-Z])([a-z]+)/', function ($matches) {
            return ' ' . strtolower($matches[1]) . $matches[2];
        }, $label);

        // Add a space before any capital letter block that is at the end of the string
        $labelWithSpaces = preg_replace('/([a-z])([A-Z]+)$/', '$1 $2', $labelWithSpaces);

        // The first letter should be uppercase
        return ucfirst(trim($labelWithSpaces));
    }
public static function name_to_label ( $ fieldName ) { // Handle dot delimiters if ( strpos ( $ fieldName , '.' ) !== false ) { $ parts = explode ( '.' , $ fieldName ) ; // Ensure that any letter following a dot is uppercased, so that the regex below can break it up // into words $ label = implode ( array_map ( 'ucfirst' , $ parts ) ) ; } else { $ label = $ fieldName ; } // Replace any capital letter that is followed by a lowercase letter with a space, the lowercased // version of itself then the remaining lowercase letters. $ labelWithSpaces = preg_replace_callback ( '/([A-Z])([a-z]+)/' , function ( $ matches ) { return ' ' . strtolower ( $ matches [ 1 ] ) . $ matches [ 2 ] ; } , $ label ) ; // Add a space before any capital letter block that is at the end of the string $ labelWithSpaces = preg_replace ( '/([a-z])([A-Z]+)$/' , '$1 $2' , $ labelWithSpaces ) ; // The first letter should be uppercase return ucfirst ( trim ( $ labelWithSpaces ) ) ; }
Takes a field name and converts camelcase to spaced words. Also resolves combined field
names with dot syntax to spaced words.

Examples:

- 'TotalAmount' will return 'Total amount'
- 'Organisation.ZipCode' will return 'Organisation zip code'

@param string $fieldName

@return string
Takes a field name and converts camelcase to spaced words . Also resolves combined field names with dot syntax to spaced words .