Skip to content

Instantly share code, notes, and snippets.

@mgng
Created May 21, 2009 15:09
Show Gist options
  • Save mgng/115508 to your computer and use it in GitHub Desktop.
Save mgng/115508 to your computer and use it in GitHub Desktop.
AAをランダムに表示するやつ
<?php
// http://taggedaa.com/ からランダムに何かを表示するやつ
// コマンドラインで実行
// http://taggedaa.com/asciiart.php?id=92
$baseUrl = 'http://taggedaa.com/asciiart.php?id=';
$num = rand(1,400);
$url = $baseUrl.$num;
$src = file_get_contents($url);
$reg = '/<pre[\s]*class=\"html\">(.+)<\/pre>/uis';
preg_match($reg, $src, $m);
if (isset($m[1])) {
$str = str_replace(
array('&nbsp;', '&lt;', '&gt;', '&amp;', '&#039;', '&quot;'),
array(' ','<', '>', '&', "'", '"'),
$m[1]
);
echo "########## {$num} ###########\n\n";
echo mb_convert_encoding($str, 'SJIS-win', 'UTF-8');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment