file()関数などでメモリをバカ食いしたくない時におすすめ。
$filePath = '/path/to/file.txt';
$count = exec('wc -l '.$filePath);
$count = trim(str_replace($filePath, '', $count));
こんな感じで取得可能。
file()関数などでメモリをバカ食いしたくない時におすすめ。
$filePath = '/path/to/file.txt';
$count = exec('wc -l '.$filePath);
$count = trim(str_replace($filePath, '', $count));
こんな感じで取得可能。
laravelのコアファイルより発掘。
function array_set(&$array, $key, $value)
{
if (is_null($key)) return $array = $value;
$keys = explode('.', $key);
while (count($keys) > 1)
{
$key = array_shift($keys);
if ( ! isset($array[$key]) or ! is_array($array[$key]))
{
$array[$key] = array();
}
$array =& $array[$key];
}
$array[array_shift($keys)] = $value;
}
使い方は下記の通り
// $array['user']['name'] にセットしたい場合 array_set($array, 'user.name', 'Value'); // $array['user']['name']['first'] にセットしたい場合 array_set($array, 'user.name.first', 'Value');
laravelのコアファイルより発掘。
function get_file_size($size)
{
$units = array('Bytes', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB');
return @round($size / pow(1024, ($i = floor(log($size, 1024)))), 2).' '.$units[$i];
}
テーブルrowはアニメーションに対応していないため、ちょっとトリッキーなことをしないとslideDown、slideUpが出来ない。
今回それを簡単に実現してくれるすばらしいプラグインをstackoverflowで見つけたので保存代わりにメモ。
(function($) {
var sR = {
defaults: {
slideSpeed: 400,
easing: false,
callback: false
},
thisCallArgs: {
slideSpeed: 400,
easing: false,
callback: false
},
methods: {
up: function (arg1,arg2,arg3) {
if(typeof arg1 == 'object') {
for(p in arg1) {
sR.thisCallArgs.eval(p) = arg1[p];
}
}else if(typeof arg1 != 'undefined' && (typeof arg1 == 'number' || arg1 == 'slow' || arg1 == 'fast')) {
sR.thisCallArgs.slideSpeed = arg1;
}else{
sR.thisCallArgs.slideSpeed = sR.defaults.slideSpeed;
}
if(typeof arg2 == 'string'){
sR.thisCallArgs.easing = arg2;
}else if(typeof arg2 == 'function'){
sR.thisCallArgs.callback = arg2;
}else if(typeof arg2 == 'undefined') {
sR.thisCallArgs.easing = sR.defaults.easing;
}
if(typeof arg3 == 'function') {
sR.thisCallArgs.callback = arg3;
}else if(typeof arg3 == 'undefined' && typeof arg2 != 'function'){
sR.thisCallArgs.callback = sR.defaults.callback;
}
var $cells = $(this).find('td');
$cells.wrapInner('<div class="slideRowUp" />');
var currentPadding = $cells.css('padding');
$cellContentWrappers = $(this).find('.slideRowUp');
$cellContentWrappers.slideUp(sR.thisCallArgs.slideSpeed,sR.thisCallArgs.easing).parent().animate({
paddingTop: '0px',
paddingBottom: '0px'},{
complete: function () {
$(this).children('.slideRowUp').replaceWith($(this).children('.slideRowUp').contents());
$(this).parent().css({'display':'none'});
$(this).css({'padding': currentPadding});
}});
var wait = setInterval(function () {
if($cellContentWrappers.is(':animated') === false) {
clearInterval(wait);
if(typeof sR.thisCallArgs.callback == 'function') {
sR.thisCallArgs.callback.call(this);
}
}
}, 100);
return $(this);
},
down: function (arg1,arg2,arg3) {
if(typeof arg1 == 'object') {
for(p in arg1) {
sR.thisCallArgs.eval(p) = arg1[p];
}
}else if(typeof arg1 != 'undefined' && (typeof arg1 == 'number' || arg1 == 'slow' || arg1 == 'fast')) {
sR.thisCallArgs.slideSpeed = arg1;
}else{
sR.thisCallArgs.slideSpeed = sR.defaults.slideSpeed;
}
if(typeof arg2 == 'string'){
sR.thisCallArgs.easing = arg2;
}else if(typeof arg2 == 'function'){
sR.thisCallArgs.callback = arg2;
}else if(typeof arg2 == 'undefined') {
sR.thisCallArgs.easing = sR.defaults.easing;
}
if(typeof arg3 == 'function') {
sR.thisCallArgs.callback = arg3;
}else if(typeof arg3 == 'undefined' && typeof arg2 != 'function'){
sR.thisCallArgs.callback = sR.defaults.callback;
}
var $cells = $(this).find('td');
$cells.wrapInner('<div class="slideRowDown" style="display:none;" />');
$cellContentWrappers = $cells.find('.slideRowDown');
$(this).show();
$cellContentWrappers.slideDown(sR.thisCallArgs.slideSpeed, sR.thisCallArgs.easing, function() { $(this).replaceWith( $(this).contents()); });
var wait = setInterval(function () {
if($cellContentWrappers.is(':animated') === false) {
clearInterval(wait);
if(typeof sR.thisCallArgs.callback == 'function') {
sR.thisCallArgs.callback.call(this);
}
}
}, 100);
return $(this);
}
}
};
$.fn.slideRow = function(method,arg1,arg2,arg3) {
if(typeof method != 'undefined') {
if(sR.methods[method]) {
return sR.methods[method].apply(this, Array.prototype.slice.call(arguments,1));
}
}
};
})(jQuery);
■使い方
普通
$('#row_id').slideRow('down');
$('#row_id').slideRow('up');
応用
$('#row_id').slideRow('down', 500); //スライドスピード
$('#row_id').slideRow('down', 500, function() { alert('Row available'); }); // スライドスピードとコールバック関数
$('#row_id').slideRow('down', 500, 'linear', function() { alert('Row available'); }); // スライドスピード、イージングオプション、コールバック関数
$('#row_id').slideRow('down', {slideSpeed: 500, easing: 'linear', callback: function() { alert('Row available');} }); // オプションをオブジェクトで渡すことも可能
これは痒いところに手が届いた神プラグイン。
めも。
var_dump(apache_request_headers());
↓
array(8) {
["Host"]=>
string(16) "manage.local.lcl"
["Connection"]=>
string(10) "keep-alive"
["Cache-Control"]=>
string(9) "max-age=0"
["Accept"]=>
string(74) "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"
["User-Agent"]=>
string(109) "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.107 Safari/537.36"
["Accept-Encoding"]=>
string(17) "gzip,deflate,sdch"
["Accept-Language"]=>
string(23) "ja,en-US;q=0.8,en;q=0.6"
["Cookie"]=>
string(36) "PHPSESSID=df9qela04cojq3piqd3b50l4e3"
}
めも。
var_dump(apache_response_headers());
↓
array(4) {
["X-Powered-By"]=>
string(9) "PHP/5.3.3"
["Expires"]=>
string(29) "Thu, 19 Nov 1981 08:52:00 GMT"
["Cache-Control"]=>
string(62) "no-store, no-cache, must-revalidate, post-check=0, pre-check=0"
["Pragma"]=>
string(8) "no-cache"
}
ということで独自関数のメモ。
function simplexmlLoadString($str,$class_name = "SimpleXMLElement",$options = 0){
$search = array("\0", "\x01", "\x02", "\x03", "\x04", "\x05", "\x06"
, "\x07", "\x08", "\x0b", "\x0c", "\x0e", "\x0f");
$str = str_replace($search, '', $str);
$str = preg_replace('/[\x00-\x08]/','',$str);
$str = preg_replace('/[\x0B-\x0C]/','',$str);
$str = preg_replace('/[\x0E-\x1F]/','',$str);
$str = mb_convert_encoding($str,'eucjp-win','UTF-8');
$str = mb_convert_encoding($str,'SJIS-win','eucjp-win');
$str = mb_convert_encoding($str,'UTF-8','SJIS-win');
$data = simplexml_load_string($str,$class_name,$options);
return $data;
}
面白いことを発見したのでメモ。
for($i = 'a'; $i != 'aa'; $i++) {
echo "$i\n";
}
なんとこれでa to zが出力される。
大発見。