Skip to content

Instantly share code, notes, and snippets.

View shouhei's full-sized avatar

Shouhei shouhei

  • japan
View GitHub Profile
@shouhei
shouhei / delet_repetition_associative_array.php
Created December 21, 2013 03:53
重複した連想配列の中身を削除するスクリプト
<?php
$target_ary = array();
$eval_ary=array();
$result_ary = array();
foreach($target_ary as $key => $value){
if(!in_array($value, $eval_ary)){
$eval_ary[] = $value;
$result_ary[] = $value;
}
}
@shouhei
shouhei / emuTimenow.php
Created February 12, 2014 14:48
Ruby Tine.now -> php Datetime
$date = new DateTime('NOW');
$time_str = preg_replace("/\+/"," +",preg_replace("/T/"," ", $date->format(DATE_ISO8601)));
@shouhei
shouhei / datetime.php
Created February 13, 2014 06:31
PHP setting timezone example
<?php
$date_utc = new DateTime();
$date_utc->setTimezone( new DateTimezone('UTC') );
echo preg_replace("/\+/"," +",preg_replace("/T/"," ",$date_utc->format(DATE_ISO8601))).PHP_EOL;
$date = new DateTime();
$date->setTimezone( new DateTimezone('Asia/Tokyo') );
echo preg_replace("/\+/"," +",preg_replace("/T/"," ",$date->format(DATE_ISO8601))).PHP_EOL;
@shouhei
shouhei / RandStr.php
Created March 10, 2014 07:15
make random strings to use php
<?php
class RandStr{
private $small = 'abcdefghjiklmnopqrstuvwxyz';
private $large = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
private $num = '0123456789';
@shouhei
shouhei / writeAndZip.php
Created April 22, 2014 23:38
php -S localhost:8888 sample.php とかやると、http://localhost:8888/sample.phpがcsv形式のファイルを生成して、ダウンロードさせるようなページになります。
<?php
exec("rm *.csv");
exec("rm *.zip");
$datas = array();
$datas[] = "hoge,hoge,hoge,hoge\nhoge,hoge,hoge";
$datas[] = "fizz,buzz,fizzbuzz\nfizz,buzz,fizzbuzz";
$csv_list = array();
@shouhei
shouhei / bootstrap.php
Created May 11, 2014 07:18
cakeの日付ごとの独自ログ
define('SQL_SAVE', 'sql_save');
$save_log_file = date('Ymd').'_sql_save';
CakeLog::config('sql_save', array(
'engine' => 'FileLog',
'types' => array('sql_save'),
'file' => $save_log_file,
));
@shouhei
shouhei / AppModel.php
Created May 11, 2014 07:19
Appモデルに打ち込めばsaveのログが全部取れるやーつ
public function afterSave(){
$data = $this->getDataSource();
$all_log = $data->getLog();
$last_log = end($all_log['log']);
$last_query = $last_log['query'];
$this->log($last_log['query'],SQL_SAVE);
}
@shouhei
shouhei / wordpress.conf
Created May 19, 2014 16:29
wordpressをnginx+php-fpmで動かすためのやーつ
listen 80;
server_name ;#ドメイン名
root /path/to/wordpress; #ワードプレスのパス
index index.php;
error_log /path/to/log/error.log;#エラーログへのパス
access_log /path/to/log/sccess.log;#アクセスログへのパス
try_files $uri $uri/ /index.php?q=$uri&$args;
@shouhei
shouhei / parse_referrer_query.php
Last active August 29, 2015 14:01
リファラのクエリーをうまいこと分解するやーつ。
function perse_referrer_query(){
if(isset($_SERVER['HTTP_REFERER'])){
$referrer = parse_url(urldecode($_SERVER['HTTP_REFERER']));
$tmp_queries = explode('&',$referrer['query']);
$queries = array();
foreach($tmp_queries as $query){
$tmp = explode('=',$query);
$queries[$tmp[0]] = $tmp[1];
}
}
@shouhei
shouhei / space_compress.php
Created May 20, 2014 06:25
全角スペースと半角スペースを一つの半角スペースに
function space_compress($str){
return preg_replace('/\s+/', ' ', preg_replace('/ /', ' ',$str));
}