Skip to content

Instantly share code, notes, and snippets.

@wgkoro
Created March 31, 2014 07:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wgkoro/9886846 to your computer and use it in GitHub Desktop.
Save wgkoro/9886846 to your computer and use it in GitHub Desktop.
PHPでよく使うやつ
<?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