Most of the php development project, I need to convert camelcase strings to space-separated strings. Recently while working on a project, I found I needed to convert camelcase strings to underscore separation.
Camel case is frequently used in programming and data storage. Here are a couple of ways to convert it. As usual, feel free to leave better methods in the comments below.
CamelCase to Underscore–
//example: parseServerInfo to parse_server_info
$string = preg_replace(’/(?<=\\w)(?=[A-Z])/',"_$1", $string);
$string = strtolower($string);
CamelCase to Spaces–
//example:BachJS to Bach J S
$string = preg_replace(’/(?<=\\w)(?=[A-Z])/’,” $1″, $string);
$string = trim($string);
Incoming search terms:
- convert camelcase to underscore online (3)
- camel-case to underscore spaced (1)
- ruby camelcase to underscore space (1)
- ruby camelcase to spaces (1)
- rails space camelcase (1)
- php underscore to camelcase code convert (1)
- php underscore or camel (1)
- php convert camelcase to underscore (1)
- php convert camel case to spaces (1)
- php change camelcase to underscore (1)