スポンサーサイト
URL変更のお知らせ
この度サイトを移転しました。
■移転先サイトURL
http://www.kakimasse.net/
このブログはそのまま残しておきますが、今後新しい記事はhttp://www.kakimasse.net/にアップしていきます。 今後ともKAKIMASSEをよろしくお願い致します。
■移転先サイトURL
http://www.kakimasse.net/
このブログはそのまま残しておきますが、今後新しい記事はhttp://www.kakimasse.net/にアップしていきます。 今後ともKAKIMASSEをよろしくお願い致します。
Linux:ディレクトリ以下を再帰的にgrepしたい
特定のディレクトリ以下から、指定した文字列を含むファイルを検索したいときのコマンド。
その結果をxargsで grep "hogehoge"に渡しています。
スバラシイ!
参考:xargs - Wikipedia
ディレクトリ以下を再帰的にgrepする
find ./ -name '*' | xargs grep "hogehoge"
PHPファイル限定なら
find ./ -name '*.php' | xargs grep "hogehoge"
find ./ -name '*'の部分が対象ファイルでfind ./ -name '*' | xargs grep "hogehoge"
PHPファイル限定なら
find ./ -name '*.php' | xargs grep "hogehoge"
その結果をxargsで grep "hogehoge"に渡しています。
スバラシイ!
参考:xargs - Wikipedia
PHP:phpでgzip (.gz) ファイルを作成するには?
PHPマニュアルにありました。
http://php.net/manual/ja/function.gzopen.php
http://php.net/manual/ja/function.gzopen.php
<?php
$file = 'sample.gz';
$gz = gzopen ( $file, 'w9' );
gzwrite ( $gz, $content );
gzclose ( $gz );
?>
これで $content の内容が書き込まれたファイルsample.gzが作成されます。$file = 'sample.gz';
$gz = gzopen ( $file, 'w9' );
gzwrite ( $gz, $content );
gzclose ( $gz );
?>
PHP:年(Y)と週番号(W)からタイムスタンプを取得する方法
例えば今日が何年の第何週目かを知るには下の関数で取得出来ますが、

ちなみに第1週〜9週はどうするかというと、
<?php
date('Y-W');
?>
date('Y-W');
?>
⇒今日が2010年11月12日なら 2010-45 と表示されます。
でも、2010年の45週は何月何日なのかを知りたい時がありました。
で、そんな時どうするのかのメモ。
一発で簡単に求められます。
<?php
$ret=strtotime('2010W45');
?>
$ret=strtotime('2010W45');
?>
⇒2010年45週のタイムスタンプ 1289142000 が求められます。
後はdate('Y/n/j H:i:s', $ret);などとして好きなフォーマットで出力可能です。
さらに週の曜日指定をしたい場合は
<?php
月曜なら
$ret=strtotime('2010W451');
$ret=strtotime('2010W45');と変わらないので省略可能です。
火曜
$ret=strtotime('2010W452');
.
.
土曜
$ret=strtotime('2010W456');
日曜
$ret=strtotime('2010W457');
?>
です。月曜なら
$ret=strtotime('2010W451');
$ret=strtotime('2010W45');と変わらないので省略可能です。
火曜
$ret=strtotime('2010W452');
.
.
土曜
$ret=strtotime('2010W456');
日曜
$ret=strtotime('2010W457');
?>
ちなみに第1週〜9週はどうするかというと、
2011年第1週月曜日(2011/01/03)
$ret=strtotime('2011W011');
2011年第9週木曜日(2011/03/03)
$ret=strtotime('2011W094');
です。
Wの後が01〜09なのがミソですね☆
$ret=strtotime('2011W011');
2011年第9週木曜日(2011/03/03)
$ret=strtotime('2011W094');
です。
Wの後が01〜09なのがミソですね☆
Apache:バーチャルホストで複数のServerAliasを使いたい
複数のサブドメインで、同じファイルにアクセスさせたい場合
(例:www.example.comでも、example.comでも、test.example.comでも、sample.example.comでも同じページを表示させたい。)
どうやったらいいのか調べてみたメモ。
Apacheのマニュアルにちゃんと載ってました。
名前ベースのバーチャルホスト - Apache HTTP サーバ
httpd.confに以下のように書けばOKです。
NameVirtualHost *:80
<VirtualHost *:80>
ServerName www.example.com
ServerAlias example.com test.example.com sample.example.com
DocumentRoot /home/example/public_html
</VirtualHost>
<VirtualHost *:80>
ServerName www.example.com
ServerAlias example.com test.example.com sample.example.com
DocumentRoot /home/example/public_html
</VirtualHost>
