इससे निपटने के तरीके के बारे में मेरी भिन्नता है। यहाँ मेरे पास दो कार्य हैं, पहला एक कैमकेले , एक कैमसेल में कुछ भी बदल जाता है और अगर पहले से ही कैमकेस होता है तो यह गड़बड़ नहीं करेगा। दूसरा अनमेलकैस कैमलकेस को अंडरस्कोर (महान कुंजी जब डेटाबेस कुंजी के साथ काम करता है) में बदल देता है।
function camelCase($str) {
$i = array("-","_");
$str = preg_replace('/([a-z])([A-Z])/', "\\1 \\2", $str);
$str = preg_replace('@[^a-zA-Z0-9\-_ ]+@', '', $str);
$str = str_replace($i, ' ', $str);
$str = str_replace(' ', '', ucwords(strtolower($str)));
$str = strtolower(substr($str,0,1)).substr($str,1);
return $str;
}
function uncamelCase($str) {
$str = preg_replace('/([a-z])([A-Z])/', "\\1_\\2", $str);
$str = strtolower($str);
return $str;
}
दोनों का परीक्षण करने देता है:
$camel = camelCase("James_LIKES-camelCase");
$uncamel = uncamelCase($camel);
echo $camel." ".$uncamel;
if (!$capitalizeFirstCharacter) { $str = lcfirst($str); }