Clean a string to make it valid as PHP variable
See more about the used regular expression at {@link http://www.regular-expressions.info/unicode.html}:
- \p{L} for any valid letter
- \p{N} for any valid number
- /u for suporting unicode
/** * Clean a string to make it valid as PHP variable * @uses GeneratorUtils::cleanString() * @param string $string the string to clean * @param bool $keepMultipleUnderscores optional, allows to keep the multiple consecutive underscores * @return string */ public static function cleanString($string, $keepMultipleUnderscores = true) { return GeneratorUtils::cleanString($string, $keepMultipleUnderscores); }
/** * */ public function testCleanString() { $this->assertSame('КонтактнаяИнформация', Utils::cleanString('КонтактнаяИнформация')); $this->assertSame('____________________', Utils::cleanString('-"\'{&~(|`\\^¨@)°]+=}£')); $this->assertSame('1234567890aBcD_EfGhI', Utils::cleanString('1234567890aBcD_EfGhI')); $this->assertSame('äöüß', Utils::cleanString('äöüß')); $this->assertSame('θωερτψυιοπασδφγηςκλζχξωβνμάέήίϊΐόύϋΰώ', 'θωερτψυιοπασδφγηςκλζχξωβνμάέήίϊΐόύϋΰώ'); }