Skip to content

Instantly share code, notes, and snippets.

View kk0917's full-sized avatar
😆
Done is better than perfect.

ko-kamenashi kk0917

😆
Done is better than perfect.
View GitHub Profile
@kk0917
kk0917 / access_log.php
Created March 17, 2016 08:34
アクセスログファイル生成
<?php
$text = file_get_contents('/path/to/mypage_login.log');
$target = file_get_contents('/path/to/member_num.txt');
$member_num = explode("\n", $target);
$match_num = [];
foreach ($member_num as $num) {
$search = strpos($text, $num);
if ($search !== false) {
@kk0917
kk0917 / calc_money_type.php
Last active February 24, 2016 22:42
金種計算プログラム
<?php
$coin_type = [1 => 10, 2 => 50, 3 => 100, 4 => 500];
$change = $argv[2] - $argv[1];
echo '代金:' . $argv[1] . "\n";
echo 'お金:' . $argv[2] . "\n";
echo '釣り:' . $change . "\n\n";
for ($i = 3; $i >= 1; $i--){
@kk0917
kk0917 / count_total_of_days.php
Last active February 16, 2016 23:12
通算日数計算プログラム
<?php
$days_per_month = [
[1 => 31, 2 => 28, 3 => 31, 4 => 30, 5 => 31, 6 => 30, 7 => 31, 8 => 31, 9 => 30, 10 => 31, 11 => 30, 12 => 31],
[1 => 31, 2 => 59, 3 => 90, 4 => 120, 5 => 151, 6 => 181, 7 => 212, 8 => 243, 9 => 273, 10 => 304, 11 => 334, 12 => 365]
];
$month = rand(1, 12);
$date = rand(1, $days_per_month[0][$month]);
echo $month . '月' . $date . '日までの通算日数:';
@kk0917
kk0917 / ok_janken.php
Last active February 11, 2016 23:19
OKじゃんけん勝敗判定プログラム
<?php
$hand = array('グー', 'チョキ', 'パー', 'OK');
$ok_used = array('未', '済');
$okFlg_taro = 0;
$okFlg_hanako = 0;
// 10回勝負で太郎と花子が出した手に応じて勝敗を出力
for($i = 1; $i <= 10; $i++) {
/**
@kk0917
kk0917 / janken.php
Last active February 8, 2016 23:24
じゃんけん勝敗判定プログラム
<?php
// じゃんけんに見立てて0~2までのランダムな数字を各変数にセット
$taro = rand(0, 2);
$hanako = rand(0, 2);
// 各数字をキーにしたじゃんけんの手を配列に格納し、各自の出した手として出力
$hand = array(0 => 'グー', 1 => 'チョキ', 2 => 'パー');
echo '太郎:' . "[{$taro}] " . $hand[$taro] . '<br>';
echo '花子:' . "[{$hanako}] " . $hand[$hanako] . '<br>';
@kk0917
kk0917 / class_timeMeaturer.php
Created November 4, 2015 08:07
処理時間計測クラス
<?php
/**
* 出典:
* http://www.objective-php.net/basic/abstract
*/
abstract class TimeMeasurer
{
abstract protected function process();
@kk0917
kk0917 / control_nslookup.php
Created October 28, 2015 23:52
IPアドレス&ホスト名検索フォーム
<html>
<head>
<title>IPアドレス&ホスト名検索フォーム | Webアプリケーション スーパーサンプル</title>
</head>
<body>
<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="POST">
<table>
<tr>
<td>IPアドレスまたはホスト名:<input type="text" name="host"></td>
@kk0917
kk0917 / file_getMetaTags.php
Last active October 14, 2015 00:03
指定したURLのメタタグの内容を表示する
<html>
<head>
<title>メタタグの内容を表示する | Webアプリケーション スーパーサンプル</title>
</head>
<body>
<?php
/**
* 出典:
@kk0917
kk0917 / function_replace.php
Created October 8, 2015 02:38
URLをスラッグ化する関数
<?php
public function slugify($text)
{
// 非文字や数字を'-'に置換する
$text = preg_replace('#[^\\pL\d]+#u', '-', $text);
// 前後の'-'を取り除く
$text = trim($text, '-');
@kk0917
kk0917 / file_rename.php
Last active October 8, 2015 00:26
ファイル名を変更する
<html>
<head>
<title>ファイル名を変更する | Webアプリケーション スーパーサンプル</title>
</head>
<body>
<?php
/**
* 出典: