memo

memo dayo.

2010-04-28から1日間の記事一覧

二次元連想配列を並べ替える

php

function ary_orderby (&$ary_param, $str_orderby, $bol_desc=False) { if (strlen($str_orderby) === 0) { return False; } $ary_sortkey = array(); foreach ($ary_param as $idx_1 => $val_1){ $ary_sortkey[$idx_1] = $val_1[$str_orderby]; unset($idx…

指定文字列に挟まれた文字列をすべて配列として取得する

php

function ary_extraction ($str_old, $str_from, $str_to){ $ary_return = array(); while (True) { $str_tmp = str_extraction($str_old, $str_from, $str_to, True); if ($str_tmp === False) { break; } $str_old = str_replace($str_tmp, '', $str_old);…

指定文字列に挟まれた文字列を取得する

php

function str_extraction ($str_old, $str_from, $str_to, $plus_flag=False){ $int_from = strpos($str_old, $str_from); if ($int_from === False) { return False; } else { $int_from = $int_from + strlen($str_from); } $int_to = strpos($str_old, $s…

配列をTSVファイルとして書き込む

php

function ary2tsv ($file_name, $ary_param) { $bol_return = False; if (count($ary_param) === 0) { return $bol_return; } if (is_file($file_name) === False) { touch($file_name); chmod($file_name, 0777); } $int_line = 0; $fp = fopen($file_name,…

TSVファイルを配列として読み込む

php

function tsv2ary ($file_name) { $ary_return = array(); if (is_file($file_name) === False) { return False; } $int_line = 0; $ary_master = array(); $fp = fopen($file_name, 'rb'); while ( ($str_tmp = fgets($fp)) !== False) { $str_tmp = str_re…

ファイル出力する

php

function write_file ($file_name, $file_content, $mode='wb') { if (is_file($file_name) === False) { touch($file_name); chmod($file_name, 0777); } if ( ($fp = fopen($file_name, $mode)) === False) { return False; } if ( (fwrite($fp, $file_con…

タブとキャリッジリターンとラインフィードを削除する

php

function trim_nl ($str_param) { $str_param = str_replace("\t", '', $str_param); $str_param = str_replace("\r\n", '', $str_param); $str_param = str_replace("\r", '', $str_param); $str_param = str_replace("\n", '', $str_param); $str_param = …