[regex] camelCase to normal text

Associate
Joined
21 May 2003
Posts
1,365
I need to convert a string in camel case to normal text, i.e.

"thisIsAString" to "this is a string"

using PHP and preg_replace but I'm stumped, any ideas?

PHP:
$text = "thisIsAString";

$text = unCamelize($text);

function unCamelize($text)
{
  $pattern = '([A-Z])';
  $replace = '$1';
  $text = strtolower(preg_replace($pattern, $replace, $text));
  
  return $text;
}
 
Back
Top Bottom