|
Amazonで書籍を探す:
Java ブログ村で他のブログを探す: この記事を・・・ Twitterでつぶやく Googleブックマークする Yahoo!ブックマークする livedoorクリップする newsingする Choixする Buzzurlする イザ!ブックマークする FC2ブックマークする ニフティクリップする del.icio.usする はてなブックマークする |
|
Amazonで書籍を探す:
Java ブログ村で他のブログを探す: この記事を・・・ Twitterでつぶやく Googleブックマークする Yahoo!ブックマークする livedoorクリップする newsingする Choixする Buzzurlする イザ!ブックマークする FC2ブックマークする ニフティクリップする del.icio.usする はてなブックマークする |
http://twitter.com/statuses/friends.json
<?phpこのクラスのインスタンスを生成して、getUsers()を実行してもらえばわかりますが、100件までしか取得できません。100件以上を取得するには、cursorというパラメータに取得した個所のcursor値を設定してやる必要があります。1〜100件の場合はcursor=-1を設定してやり、101〜200を取得する場合は、最初に取得した100件のjson情報の中にnext_cursorという項目があるので、next_cursor_strに格納されている値をcursor値としてapiを実行します。しかも、cursorパラメータを使う場合は、使わない場合にくらべて微妙にjson情報の形式が異なるので注意が必要です。これをプログラムにすると以下のようになります。
class GetFriends100{
private $screen_name;
public function __construct($screen_name){
$this->screen_name = $screen_name;
}
public function getUsers(){
$cnt = 0;
$callstr = "http://twitter.com/statuses/friends.json?screen_name=".$this->screen_name;
$ch = curl_init($callstr);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$apiresponse = curl_exec($ch);
curl_close($ch);
if ($apiresponse) {
$json = json_decode($apiresponse);
$usrs = $json->users;
foreach( $usrs as $u ) {
print("[".$cnt."]".$u->id.":".$u->name."\n");
$cnt++;
}
}
}
}
?>
<?php取得できる情報がなくなると、next_cursorの値は0に設定されます。このプログラムでは全て取得する(next_cursorが0になる)までフォローしているユーザ情報を取得します。また、前回のダダ流しプログラムにIDのパラメタを渡せるように、IDの羅列を作って戻り値とします。
class GetFriends{
private $screen_name;
public function __construct($screen_name){
$this->screen_name = $screen_name;
}
public function getUsers(){
$cursor = -1;
$cnt = 0;
$usrids = "";
do {
$callstr = "http://twitter.com/statuses/friends.json?screen_name=".$this->screen_name."&cursor=".$cursor;
$ch = curl_init($callstr);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$apiresponse = curl_exec($ch);
curl_close($ch);
if ($apiresponse) {
$json = json_decode($apiresponse);
$usrs = $json->users;
foreach( $usrs as $u ) {
print("[".$cnt."]".$u->id.":".$u->name."\n"); // 取得ユーザ表示用
if( $cnt == 0 ) {
$usrids = $u->id;
}else {
$usrids = $usrids.",".$u->id;
}
$cnt++;
}
$cursor = $json->next_cursor_str;
}
}while( $cursor > 0 );
return $usrids;
}
}
?>
|
Amazonで書籍を探す:
Java ブログ村で他のブログを探す: この記事を・・・ Twitterでつぶやく Googleブックマークする Yahoo!ブックマークする livedoorクリップする newsingする Choixする Buzzurlする イザ!ブックマークする FC2ブックマークする ニフティクリップする del.icio.usする はてなブックマークする |


<?php
$user = 'username';
$password = 'password';
$url = "http://{$user}:{$password}@stream.twitter.com/spritzer.json";
$stream = fopen($url, "r");
while ($json = fgets($stream)) {
$twitter= json_decode($json,true);
if( isset($twitter['text']) ) {
print $twitter['user']['name'].':'.$twitter['text'] . PHP_EOL;
}
}
?>
if(preg_match('/[ァ-ヶーぁ-ん]/u',$twitter['text'])) {
print $twitter['user']['name'].':'.$twitter['text'] . PHP_EOL;
}これは、出力するつぶやきを正規表現で日本語に絞っています。これで少しは意味のあるダダ流しになったのでは、ないかと思います。|
Amazonで書籍を探す:
Java ブログ村で他のブログを探す: この記事を・・・ Twitterでつぶやく Googleブックマークする Yahoo!ブックマークする livedoorクリップする newsingする Choixする Buzzurlする イザ!ブックマークする FC2ブックマークする ニフティクリップする del.icio.usする はてなブックマークする |
<?php
// エンコーディングの設定
define("MAGPIE_OUTPUT_ENCODING","UTF-8");
// twitterユーザ名
define("TWITTER_USER_NAME","kurofit");
require_once("magpierss/rss_fetch.inc");
/**
* twitterHashRssクラス
*
* @package twitterHashRss
*/
class twitterHashRss {
private $rss;
private $hashtag;
/**
* twitterHashRss()
*
* @param $hashtag ハッシュタグ文字列
* @return void
*/
function twitterHashRss($tag)
{
$url = "http://search.twitter.com/search.atom?q=%23".$tag;
$this->rss = fetch_rss( $url );
$this->hashtag = $tag;
}
/**
* ハッシュタグのRSSからHTML生成
*
* @param $cnt RSS取得件数(最大で15件)
* @return string
*/
function getHtml($cnt) {
$html = "<ul>";
$lineCnt = 0;
$locRss = $this->rss;
for($line=0;$line < isset($locRss->items[$line]); ++$line) {
$item = $locRss->items[$line];
// ユーザ名でフィルタをかける
if( false !== strpos($item['author_name'], TWITTER_USER_NAME) ){
++$lineCnt;
if( $cnt < $lineCnt ) {
// 指定回数を超えた
break;
}
$title = mb_convert_encoding($item['title'],"UTF-8","auto");
$modi = mb_convert_encoding($item['updated'],"UTF-8","auto");
// 余分な文字列を削除
$title = str_replace("#".$this->hashtag, "", $title);
// 出力
$html = $html."<li>".$title." ".date('Y/m/d', strtotime($modi))." up</li>";
}
}
$html = $html."</ul>";
if( 0 === $lineCnt ) {
$html = "none";
}
return $html;
}
/**
* ハッシュタグのRSSからHTML生成
*
* @param $cnt RSS取得件数(最大で15件)
* @return string
*/
function getLinkedHtml($cnt) {
$html = "<ul>";
$lineCnt = 0;
$locRss = $this->rss;
for($line=0;$line < isset($locRss->items[$line]); ++$line) {
$item = $locRss->items[$line];
if( false !== strpos($item['author_name'], SITE_AUTHOR) ){
++$lineCnt;
$href = mb_convert_encoding($item['link'],"UTF-8","auto");
$title = mb_convert_encoding($item['title'],"UTF-8","auto");
$modi = mb_convert_encoding($item['updated'],"UTF-8","auto");
// 余分な文字列を削除
$title = str_replace("#".$this->hashtag, "", $title);
// 出力
$html = $html."<li><a href=".$href.">".$title."</a> ".date('Y/m/d', strtotime($modi))." up</li>";
if( $cnt < $lineCnt ) {
// 指定回数を超えた
break;
}
}
}
$html = $html."</ul>";
if( 0 === $lineCnt ) {
$html = "none";
}
return $html;
}
}
?>
|
Amazonで書籍を探す:
Java ブログ村で他のブログを探す: この記事を・・・ Twitterでつぶやく Googleブックマークする Yahoo!ブックマークする livedoorクリップする newsingする Choixする Buzzurlする イザ!ブックマークする FC2ブックマークする ニフティクリップする del.icio.usする はてなブックマークする |
<?php
require_once("magpierss/rss_fetch.inc");
// エンコーディングの設定
define("MAGPIE_OUTPUT_ENCODING","UTF-8");
//取得するRSSのURL
$url = "http://harukofarm.jugem.jp/?mode=atom";
$rss = fetch_rss( $url );
// 最新件数10件に限定
array_splice($rss->items, 10);
header("Content-type:text/html;charset=UTF-8");
foreach ($rss->items as $item) {
// RSSからデータを取得
$href = mb_convert_encoding($item['link'],"UTF-8","auto");
$title = mb_convert_encoding($item['title'],"UTF-8","auto");
$modi = mb_convert_encoding($item['modified'],"UTF-8","auto");
// 取得したデータをHTMLとして組み立てる
$recentInfo = $recentInfo." ・<a href=$href>$title</a> ".date('Y/m/d', strtotime($modi))." up<BR>";
}
print($recentInfo);
?>

|
Amazonで書籍を探す:
Java ブログ村で他のブログを探す: この記事を・・・ Twitterでつぶやく Googleブックマークする Yahoo!ブックマークする livedoorクリップする newsingする Choixする Buzzurlする イザ!ブックマークする FC2ブックマークする ニフティクリップする del.icio.usする はてなブックマークする |
特定のログファイルが100KBを超えた場合、日付と時刻のファイル名でリネームする
define(LOG_FILE_PATH, "./"); // 文字列の終端は「/」で終わること
define(LOG_FILE_NAME, "access.log");
define(LOG_FILE_SIZE_MAX, 100 * 1024); // 最大ログファイルサイズ(100KB)
$log_file = LOG_FILE_PATH.LOG_FILE_NAME;
// ログファイルが存在するか?
if( file_exists($log_file) ) {
if( LOG_FILE_SIZE_MAX < filesize($log_file) ) {
// 現在の日付を取得
$time_date = gmdate("YmdHi", time() + 60*60*9);
// ログファイルを移動する
$new_file = LOG_FILE_PATH.$time_date."_".LOG_FILE_NAME;
rename($log_file, $new_file);
}
}
define(LOG_FILE_PATH, "./"); // 文字列の終端は「/」で終わること
define(LOG_FILE_NAME, "access.log");
define(LOG_FILE_SIZE_MAX, 100 * 1024); // 最大ログファイルサイズ(100KB)
define(LOG_FILE_COUNT_MAX, 50); // 保持するログファイルの数
$log_file = LOG_FILE_PATH.LOG_FILE_NAME;
// ログファイルが存在するか?
if( file_exists($log_file) ) {
if( LOG_FILE_SIZE_MAX < filesize($log_file) ) {
// 現在の日付を取得
$time_date = gmdate("YmdHis", time() + 60*60*9);
// ログファイルを移動する
$new_file = LOG_FILE_PATH.$time_date."_".LOG_FILE_NAME;
rename($log_file, $new_file);
$log_file_count = 0;
// 降順でログディレクトリのファイル一覧を取得
$log_files = scandir(LOG_FILE_PATH, 1);
// ログファイルのカウント
for($file_cnt = 0; isset($log_files[$file_cnt]); $file_cnt++ ) {
if( 0 < strrpos($log_files[$file_cnt], LOG_FILE_NAME) ) {
// *access.logファイルの数をカウント
$log_file_count++;
if( $log_file_count > LOG_FILE_COUNT_MAX ) {
// 保持ログ数を超えたファイルを削除
unlink(LOG_FILE_PATH.$log_files[$file_cnt ]);
}
}
}
}
}
|
Amazonで書籍を探す:
Java ブログ村で他のブログを探す: この記事を・・・ Twitterでつぶやく Googleブックマークする Yahoo!ブックマークする livedoorクリップする newsingする Choixする Buzzurlする イザ!ブックマークする FC2ブックマークする ニフティクリップする del.icio.usする はてなブックマークする |
// 現在の日付を取得
$time_date = gmdate("Y/m/d", time()+60*60*9);
// 現在の時刻を取得
$time_now = gmdate("H:i", time()+60*60*9);
// アクセスページの記録
$access_url = "http://".$_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"];
// IPアドレスを取得
$ip = getenv("REMOTE_ADDR");
// ホスト情報を取得する
$host = getenv("REMOTE_HOST");
if( !$REMOTE_HOST ) {
$host = gethostbyaddr($ip);
}
// 直前のURLを取得する
$prv_url = getenv("HTTP_REFERER");
if( $prv_url == "" ) {
$prv_url = "お気に入り or 直リンク";
}
// ブラウザ(クライアントソフト)の取得
$client = getenv("HTTP_USER_AGENT");
|
Amazonで書籍を探す:
Java ブログ村で他のブログを探す: この記事を・・・ Twitterでつぶやく Googleブックマークする Yahoo!ブックマークする livedoorクリップする newsingする Choixする Buzzurlする イザ!ブックマークする FC2ブックマークする ニフティクリップする del.icio.usする はてなブックマークする |
| variable | specification |
| SERVER_SOFTWARE | The name and version of the information server software answering the request (and running the gateway). Format: name/version |
| SERVER_NAME | The server's hostname, DNS alias, or IP address as it would appear in self-referencing URLs. |
| GATEWAY_INTERFACE | The revision of the CGI specification to which this server complies. Format: CGI/revision |
| SERVER_PROTOCOL | The name and revision of the information protcol this request came in with. Format: protocol/revision |
| SERVER_PORT | The port number to which the request was sent. |
| REQUEST_METHOD | The method with which the request was made. For HTTP, this is "GET", "HEAD", "POST", etc. |
| PATH_INFO | The extra path information, as given by the client. In other words, scripts can be accessed by their virtual pathname, followed by extra information at the end of this path. The extra information is sent as PATH_INFO. This information should be decoded by the server if it comes from a URL before it is passed to the CGI script. |
| PATH_TRANSLATED | The server provides a translated version of PATH_INFO, which takes the path and does any virtual-to-physical mapping to it. |
| SCRIPT_NAME | A virtual path to the script being executed, used for self-referencing URLs. |
| QUERY_STRING | The information which follows the ? in the URL which referenced this script. This is the query information. It should not be decoded in any fashion. This variable should always be set when there is query information, regardless of command line decoding. |
| REMOTE_HOST | The hostname making the request. If the server does not have this information, it should set REMOTE_ADDR and leave this unset. |
| REMOTE_ADDR | The IP address of the remote host making the request. |
| AUTH_TYPE | If the server supports user authentication, and the script is protects, this is the protocol-specific authentication method used to validate the user. |
| REMOTE_USER | If the server supports user authentication, and the script is protected, this is the username they have authenticated as. |
| REMOTE_IDENT | If the HTTP server supports RFC 931 identification, then this variable will be set to the remote user name retrieved from the server. Usage of this variable should be limited to logging only. |
| CONTENT_TYPE | For queries which have attached information, such as HTTP POST and PUT, this is the content type of the data. |
| CONTENT_LENGTH | The length of the said content as given by the client. |
| HTTP_ACCEPT | The MIME types which the client will accept, as given by HTTP headers. Other protocols may need to get this information from elsewhere. Each item in this list should be separated by commas as per the HTTP spec. |
| HTTP_USER_AGENT | The browser the client is using to send the request. General format: software/version library/version. |
|
Amazonで書籍を探す:
Java ブログ村で他のブログを探す: この記事を・・・ Twitterでつぶやく Googleブックマークする Yahoo!ブックマークする livedoorクリップする newsingする Choixする Buzzurlする イザ!ブックマークする FC2ブックマークする ニフティクリップする del.icio.usする はてなブックマークする |
|
Amazonで書籍を探す:
Java ブログ村で他のブログを探す: この記事を・・・ Twitterでつぶやく Googleブックマークする Yahoo!ブックマークする livedoorクリップする newsingする Choixする Buzzurlする イザ!ブックマークする FC2ブックマークする ニフティクリップする del.icio.usする はてなブックマークする |
<?PHP
// Excel_Reviser本体を include(または require)します。
require_once('../reviser.php');
// reviserのClassオブジェクトを新規に作成します。
$reviser=NEW Excel_Reviser;
// デフォルトは EUC-JPです。機種依存文字に対応するためには
// 文字コードを変更してください。このファイルもその文字コードで
// 保存すること
// $reviser->setInternalCharset('utf-8');
// 空白セルに文字を追加する例です
$reviser->addString(0,5,5, '0123456789');
$reviser->addString(0,5,9, '2009/11/11');
$reviser->addString(0,10,1, '〒680-0441');
$reviser->addString(0,11,1, '鳥取県×××××××××');
$reviser->addString(0,13,1, '佐藤太郎');
$reviser->addString(0,11,6, 'ご注文者と同じ住所');
$reviser->addString(0,16,3, '銀行振込み');
$reviser->addString(0,19,1, '花御所柿6個セットサイズ:2L(ご自宅用)');
$reviser->addNumber(0,19,6, 2980);
$reviser->addNumber(0,19,8, 2);
$reviser->addString(0,20,1, '花御所柿6個セットサイズ:L(ご自宅用)');
$reviser->addNumber(0,20,6, 1980);
$reviser->addNumber(0,20,8, 2);
// 代引き手数料
$reviser->addNumber(0,40,9, 0);
// 送料
$reviser->addNumber(0,41,9, 800);
// 入力出力ファイル名の設定
$readfile='./template/template_receipt.xls'; // テンプレートファイルの指定
$outfile="test.xls"; // 出力するファイル名です
// 最後に書換えを実行します
$reviser->reviseFile($readfile,$outfile)
?>
|
Amazonで書籍を探す:
Java ブログ村で他のブログを探す: この記事を・・・ Twitterでつぶやく Googleブックマークする Yahoo!ブックマークする livedoorクリップする newsingする Choixする Buzzurlする イザ!ブックマークする FC2ブックマークする ニフティクリップする del.icio.usする はてなブックマークする |
select * from onsen_info order by loc <-> point(0,0) offset 0 limit 5
|
Amazonで書籍を探す:
Java ブログ村で他のブログを探す: この記事を・・・ Twitterでつぶやく Googleブックマークする Yahoo!ブックマークする livedoorクリップする newsingする Choixする Buzzurlする イザ!ブックマークする FC2ブックマークする ニフティクリップする del.icio.usする はてなブックマークする |
Author:kurofit
IT技術関連ならなんでも興味があります。いろんなものに手を出しすぎて、結局広く浅くなって・・。ということで、忘れないようにJavaプログラムに関する情報を残してます。
掲載しているソースは自由に使っていただいて結構です。こういうやり方がいいよ!改造したよ!と、ご報告いただけると嬉しいです。
・twitter
・プロフィール詳細
REQUEST_URI HTTP_HOST gmdate HTTP_USER_AGENT REMOTE_ADDR REMOTE_HOST getenv HTTP_REFERER gethostbyaddr win32api SetFileAttributes kernel32