Created
March 31, 2014 07:07
-
-
Save wgkoro/9886846 to your computer and use it in GitHub Desktop.
PHPでよく使うやつ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Util{ | |
// アンダースコア「_」区切りでCamelCaseに変換する | |
public static function toCamelCase($string){ | |
$camel_case = ""; | |
$string_arr = explode("_", $string); | |
foreach($string_arr as $name){ | |
if(empty($name)){ continue; } | |
$camel_case .= ucwords($name); | |
} | |
return $camel_case; | |
} | |
public static function jsonDump($obj){ | |
return json_encode($obj, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP); | |
} | |
public static function jsonParse($json_str){ | |
return json_decode($json_str, true); | |
} | |
// htmlspecialcharsショートカット | |
public static function h($string){ | |
if(is_array($string)){ | |
return array_map('Util::h', $string); | |
} | |
else{ | |
return htmlspecialchars($string, ENT_QUOTES, "UTF-8"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment