[PHP]unzip

public function unzip($file,$to)
{
    $zip = new ZipArchive();
    $result = $zip->open($file);
    if($result === true){
        $result = $zip->extractTo($to);
        $zip->close();
    }
    return $result === true;
}

[MySQL]50音判定

REGEXPはマルチバイトに対応していないので、FIND_IN_SETを使用。

INSERT INTO xxx(initial_chara,gyo)
(
SELECT
SUBSTRING(tmp.name,1,1),
(CASE
WHEN FIND_IN_SET(SUBSTRING(tmp.name,1,1),'あ,い,う,え,お') THEN 'あ'
WHEN FIND_IN_SET(SUBSTRING(tmp.name,1,1),'か,き,く,け,こ,が,ぎ,ぐ,げ,ご') THEN 'か'
WHEN FIND_IN_SET(SUBSTRING(tmp.name,1,1),'さ,し,す,せ,そ,ざ,じ,ず,ぜ,ぞ') THEN 'さ'
WHEN FIND_IN_SET(SUBSTRING(tmp.name,1,1),'た,ち,つ,て,と,だ,ぢ,づ,で,ど') THEN 'た'
WHEN FIND_IN_SET(SUBSTRING(tmp.name,1,1),'な,に,ぬ,ね,の') THEN 'な'
WHEN FIND_IN_SET(SUBSTRING(tmp.name,1,1),'は,ひ,ふ,へ,ほ,ば,び,ぶ,べ,ぼ') THEN 'は'
WHEN FIND_IN_SET(SUBSTRING(tmp.name,1,1),'ま,み,む,め,も') THEN 'ま'
WHEN FIND_IN_SET(SUBSTRING(tmp.name,1,1),'や,ゐ,ゆ,ゑ,よ') THEN 'や'
WHEN FIND_IN_SET(SUBSTRING(tmp.name,1,1),'ら,り,る,れ,ろ') THEN 'ら'
WHEN FIND_IN_SET(SUBSTRING(tmp.name,1,1),'わ,を,ん') THEN 'わ'
ELSE 'ん' END
)
FROM yyy AS tmp

[CodeIgniter]get_table_names_by_dbname

$this->db->list_tables();

上記だとキャッシュから取得する。キャッシュを回避する場合下記を使用。

public function get_table_names_by_dbname($dbname)
{
    $names = array();
    $sql = "SHOW TABLES FROM {$dbname}";
    $query = $this->db->query($sql);
    foreach ($query->result_array() as $row)
    {
        if ( ! isset($key))
        {
            if (isset($row['table_name']))
            {
                $key = 'table_name';
            }
            elseif (isset($row['TABLE_NAME']))
            {
                $key = 'TABLE_NAME';
            }
            else
            {
                $key = array_keys($row);
                $key = array_shift($key);
            }
        }

        $names[] = $row[$key];
    }
    return $names;
}

[CodeIgniter]set_header

$this->output->set_header('X-Frame-Options: SAMEORIGIN');
$this->output->set_header('Cache-control: no-cache, no-store, post-check=0, pre-check=0');
$this->output->set_header('Pragma: no-cache');
$this->output->set_header('Expires: Thu, 01 Dec 1994 16:00:00 GMT');

[PHP]zip

public function zip($zipfile,$add_file)
{
    $zip = new ZipArchive();
    $result = $zip->open($zipfile, ZipArchive::CREATE);
    if($result === true)
    {
        $zip->addFile($add_file);
        $result = $zip->close();
    }
    return $result === true;
}

[AWS]FILE権限

AmazonRDSは仕様上FILE権限は付与出来ない。
故に

LOAD DATA INFILE xxxx.csv INTO TABLE wp_names FIELDS TERMINATED BY ',' ENCLOSED BY '\"' IGNORE 1 LINES;

LOAD DATA LOCAL INFILE xxxx.csv INTO TABLE wp_names FIELDS TERMINATED BY ',' ENCLOSED BY '\"' IGNORE 1 LINES;

へ変更するとよい

※余談
windows上ではパスのセパレータを/に変換しないと動かないことも

$filepath = preg_replace('/\\\\/','/',$filepath);

[PHP]echo_json

function echo_json($data)
{
    header("Content-Type: application/json; charset=utf-8");
    echo json_encode($data);
}

[PHP]is_https

public function is_https()
{
    if(!empty($_SERVER["HTTPS"]))
        return true;
    //AWS
    if(!empty($_SERVER["HTTP_X_FORWARDED_PROTO"]) && strtolower($_SERVER["HTTP_X_FORWARDED_PROTO"])==="https")
        return true;
    return false;
}