openrat-cms

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

Converter.class.php (510B)


      1 <?php
      2 
      3 
      4 namespace util\text;
      5 
      6 
      7 class Converter
      8 {
      9 	public static function toCamelCase($string) {
     10 		$string = str_replace('-', ' ', $string);
     11 		$string = str_replace('_', ' ', $string);
     12 		$string = ucwords(strtolower($string));
     13 		$string = str_replace(' ', '', $string);
     14 		$string = lcfirst($string);
     15 
     16 		return $string;
     17 	}
     18 
     19 
     20 	public static function camelToUnderscore($string, $us = "-") {
     21 
     22 		return strtolower(preg_replace(
     23 			'/(?<=\d)(?=[A-Za-z])|(?<=[A-Za-z])(?=\d)|(?<=[a-z])(?=[A-Z])/', $us, $string));
     24 	}
     25 }