Transforms string to snake case (e.g., result_string).

@param string $string Text to transform.

@return string
513445
public static function snake($string)
    {
        $string = preg_replace('#([A-Z\d]+)([A-Z][a-z])#', '\1_\2', self::camel($string));
        $string = preg_replace('#([a-z\d])([A-Z])#', '\1_\2', $string);

        return strtolower(strtr($string, '-', '_'));
    }
1089767
public static function string_to_camelcase( $string, $capitalize = true ){
  	$normalize_string = str_replace( array( '-', '_' ), ' ', $string );
  	$ucwords = ucwords( $normalize_string, ' ' );
  	$camelcase_string = str_replace(' ', '', $ucwords);
    if( ! $capitalize ) {
    	$camelcase_string = lcfirst( $camelcase_string );
    }
    return $camelcase_string;
  }
176664
protected function convertKeywords($string)
    {
        $string = str_replace('\Closure', 'Closure', $string);
        $string = str_replace('Closure', '\Closure', $string);
        $string = str_replace('dynamic', 'mixed', $string);

        return $string;
    }
1241713
private static function toCamelCase(string $text): string
    {
        if (strpos($text, '_') !== false) {
            $text = str_replace(' ', '', ucwords(str_replace('_', ' ', $text)));
        }
        $text[0] = strtolower($text[0]);

        return $text;
    }
681495
public static function snakecaseToCamelcase(string $string, bool $lower = false): string
    {
        $words = explode('_', $string);

        array_walk($words, function (&$word, $index) {
            $word = ucfirst($word);
        });

        if ($lower) {
            return lcfirst(implode($words));
        }

        return implode($words);
    }
488944
public function bumpyCase($string)
    {
        $words = explode('_', $string);
        foreach ($words as &$word) {
            $word = ucfirst($word);
        }
        unset ($word);
        
        $camelCase = implode('', $words);
        return $camelCase;
    }
773472
public static function safe(string $string) : string
  {
    $split = str_split($string);

    foreach($split as $k => $char) {
      if (str_contains('~!@#$%^&*()_-=+<>/\?;:{}[]|,.', $char)) {
        unset($split[$k]);
      }
    }

    return implode('', $split);
  }
438425
public function nl2p($string)
    {
        // replace lineFeed with <br /> tag
        $lineFeed = chr(10);
        $value = preg_replace('#'.$lineFeed.'#', '<br />', $string);

        // replace double <br /> tags with </p><p> tags
        $pattern = '#<br />([ ]*)<br />#';
        $replacement = '</p><p>';
        $result = preg_replace($pattern, $replacement, $value);

        return $result;
    }
708937
def _to_snake_case(string):
        
        sub_string = r'\1_\2'
        string = REGEX_CAMEL_FIRST.sub(sub_string, string)
        return REGEX_CAMEL_SECOND.sub(sub_string, string).lower()
686803
public static function toSnakecase($string) {

		if(false === is_string($string)) {
			return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($string)), E_USER_ERROR);
		}

		return ltrim(strtolower(preg_replace('/[A-Z]([A-Z](?![a-z]))*/', '_$0', $string)), '_');
	}
849
private function applyTransformers(string $string): string
    {
        foreach (Transformer::getAll() as $transformer) {
            $string = $transformer($string);
        }

        return $string;
    }
1247192
public static function underscoredToLowerCamelCase($string) {
		$upperCamelCase = str_replace(' ', '', ucwords(str_replace('_', ' ', self::strtolower($string))));
		$lowerCamelCase = self::lcfirst($upperCamelCase);
		return $lowerCamelCase;
	}
316833
def decamel_to_snake(string):
    
    strings = [decamel(word) if not word.isupper() else word.lower()
               for word in string.split()]
    return "_".join([snake(dstring)for dstring in strings])
549480
private function getStringToCamelCase( $string )
	{
		$words = preg_split( "#[^a-z0-9]#i", $string );
		$words = array_map( 'ucfirst', $words );

		return join( '', $words );
	}
1136120
def snake_case(string):
    
    if not string:
        return string
    string = string.replace('-', '_').replace(' ', '_')
    return de_camel(string)
1075240
public function apply(string $string) : string
    {
        return str_replace($this->search, $this->replace, $string);
    }
814111
static String convertToSnakeCase(final String string) {
        final StringBuilder builder = new StringBuilder();
        boolean isPrevCharLowerCase = false;
        for (int index = 0; index < string.length(); index++) {
            final char character = string.charAt(index);
            if (character == ' ') {
                builder.append("_");
            } else if (Character.isUpperCase(character) && isPrevCharLowerCase) {
                builder.append("_").append(Character.toLowerCase(character));
            } else {
                builder.append(Character.toLowerCase(character));
            }
            isPrevCharLowerCase = Character.isLowerCase(character);
        }
        return builder.toString();
    }