19
16

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

snake_caseとCamelCaseの相互変換

Last updated at Posted at 2012-12-26
snake->Camel
<?php
function camelize($str) {
  $str = ucwords($str, '_');
  return str_replace('_', '', $str);
}

// test
echo camelize('foo_goo_hoo'); //FooGooHoo
Camel->snake
<?php
function snakize($str) {
  $str = preg_replace('/[a-z]+(?=[A-Z])|[A-Z]+(?=[A-Z][a-z])/', '\0_', $str);
  return strtolower($str);
}

// test
echo snakize('getURLAndInfo'); //get_url_and_info

この辺参考になります。(LICENSEはdietcake参照)
https://github.com/dietcake/dietcake/blob/master/core/inflector.php#L28

19
16
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
19
16

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?