Created
March 28, 2012 11:30
-
-
Save miyukki/2225539 to your computer and use it in GitHub Desktop.
role.php is print text in current directory on display, and delete printed text.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
while(true){ | |
if ($handle = opendir('./')) { | |
/* ディレクトリをループする際の正しい方法です */ | |
while (false !== ($file = readdir($handle))) { | |
if(endWith($file, '.txt')) { | |
printComment($file); | |
} | |
} | |
closedir($handle); | |
} | |
} | |
function printComment($file) { | |
$fp = @fopen($file, 'r+'); | |
while( !feof( $fp ) ){ | |
echo fgets( $fp, 9182 ); | |
} | |
flock($fp, LOCK_EX); | |
ftruncate($fp,0); | |
flock($fp, LOCK_UN); | |
fclose($fp); | |
} | |
function endWith($haystack, $needle){ | |
$length = (strlen($haystack) - strlen($needle)); | |
// 文字列長が足りていない場合はFALSEを返します。 | |
if($length < 0) return FALSE; | |
return strpos($haystack, $needle, $length) !== FALSE; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment