2004-05-10 Mon
JpGraph
- Summary
JpGraph is an OO class library for PHP >=4.2.0.
The only other hard requirement is that the PHP installation suppports the GD library which most modern PHP installations do.
- Reference
JpGraph - OO Graph Library for PHP
http://www.aditus.nu/jpgraph/
2004-02-16 Mon
XML_RSS
- XML_RSSパッケージのインストール
# pear install xml_rss
- サンプル
<?php require_once("XML/RSS.php"); $rss =& new XML_RSS("http://www.pat.hi-ho.ne.jp/dimension/home.rss"); $rss->parse(); echo "<ul>\n"; foreach ($rss->getItems() as $item) { echo "<li><a href=\"" . $item['link'] . "\">" . mb_convert_encoding($item['title'], mb_internal_encoding(), 'auto') . "</a></li>\n"; } echo "</ul>\n"; ?>
- Reference
XML_RSS
Do You PHP? - PEARのXML_RSSでRSSしてみる
http://www.pat.hi-ho.ne.jp/dimension/sample/sample_xml_pear_rss.shtml
2004-02-16 Mon
MagpieRSS
- Summary
PHPで使えるRSSパーサー
- サンプル
<?php require_once 'rss_fetch.inc'; $url = 'http://www.hyuki.com/yukiwiki/wiki.cgi?RssPage'; $rss = fetch_rss($url); $title = $rss->channel['title']; $title = mb_convert_encoding($title, "SJIS", "auto"); echo "<h2>$title</h2>\n"; echo "<ul>\n"; foreach ($rss->items as $item ) { $title = $item[title]; $title = mb_convert_encoding($title, "SJIS", "auto"); $url = $item[link]; echo "<li><a href=\"$url\">$title</a></li>\n"; } echo "</ul>\n"; ?>
- Reference
YukiWiki - MagpieRSS
http://www.hyuki.com/yukiwiki/wiki.cgi?MagpieRSS
2004-01-20 Tue
VimでPHP関数の辞書を作成する方法
- vim.sourceforge.net から PHP.dictを取得
$HOME/.vim/PHP.dict に保存
- .vimrc に以下を記述
autocmd FileType php :set dictionary=$HOME/.vim/PHP.dict
- 方法
Ctrl-x Ctrl-k
- Reference
Vim で PHP 関数の辞書を作成する方法についてのメモ
http://www.asahi-net.or.jp/~wv7y-kmr/memo/vim_php.html
PHP-dictionary - A PHP-dictionary as a building stone for scripts : vim online
http://vim.sourceforge.net/scripts/script.php?script_id=534
2004-01-10 Sat
CSV形式でのデータのダウンロード
- 方法
1. サーバ側でCSVファイルを作成し,ダウンロードさせる
2. Header関数でContent-typeを出力し,整形したデータをそのまま返す
- サンプル
/* HTTPヘッダの出力 */ Header("Content-disposition: attachment; filename=test.csv"); Header("Content-type: application/octet-stream; name=test.csv"); /* データを出力 */ echo $contents;
- Reference
Do You PHP? - CSV形式でのデータダウンロード
http://www.pat.hi-ho.ne.jp/dimension/sample/sample_ora_csv.shtml
2004-01-10 Sat
日付操作処理の関数
- Program Rabo提供の date.php
----年--月--日の--日後を計算可能
- Reference
Program Rabo - PHPプログラム - 日付操作処理
http://www.spicy-islands.com/php/date/
2004-01-06 Tue
連想配列をPush
- こんな方法もある
$arr = array();
$arr += array("0" => "apple");
$arr += array("1" => "orange");
- Reference
PHP-users ML - [PHP-users 13781] Re: array_pushで連想配列
http://ns1.php.gr.jp/pipermail/php-users/2003-March/014313.html
2003-11-23 Sun
セッション管理
- 値の渡し方
$_SESSION['idx'] = $idx;
<form action="somewhere.php?= SID ?>"> // セッションID 管理
- 方法
// セッションを開始/復元
session_start();
// セッション変数登録
session_register(idx);
$_SESSION['idx'] で取り出せる.
- Reference
PHP 基礎編6 - 数値関数、その他
rand、floor、ceil、round、$REMOTE_ADDR - SAK Streets
http://homepage2.nifty.com/sak/w_sak3/doc/sysbrd/php_k06.htm
2003-11-05 Wed
画像からメタ情報を取得
- 方法
<?php $size = GetImageSize("img/flag.jpg"); ?> <img src="img/flag.jpg" <?php echo $size[3]; ?> />
- $size[3] の中身
width="120" height="40"
- つまり
<img src="img/flag.jpg" width="120" height="40" />2003-11-05 Wed
Magpie RSS - PHP RSS Parser
- Summary
PHPでRSSを扱うためのParser
- Reference
Magpie RSS - PHP RSS Parser
http://magpierss.sourceforge.net/
2003-11-01 Sat
連想配列をキーでソートして走査
- サンプル
$fruits = array ( "d"=>"lemon", "a"=>"orange", "b"=>"banana", "c"=>"apple"' ); ksort ($fruits); reset ($fruits); while (list ($key, $val) = each ($fruits)) { echo "$key = $val\n"; }
- 出力
a = orange b = banana c = apple d = lemon
- Reference
PHP Manual - ksort
2003-10-23 Thu
定数の使用法
- 定義方法
define('NUM',12345); // 整数,浮動小数点の定義
define('NKF_PATH','/usr/bin/nkf'); // 文字型の定義
- 使用上の注意 - echo
×
echo "nkfへのパスは = NKF_PATH"; // nkfへのパスは = NKF_PATH
○
echo "nkfへのパスは = ".NKF_PATH; // nkfへのパスは = /usr/bin/nkf
- 使用上の注意 - exec
×
exec("NKF_PATH NKF_OPTION $import_file > $import_file_euc");
○
exec(NKF_PATH." ".NKF_OPTION." $import_file > $import_file_euc");
2003-10-20 Mon
mb_ereg の未定義エラー
- phpinfoを見ても
--enable-mbstring 付き
Multibyte (Japanese) Support もOK
- 原因
--enable-mbregex 付きで configure されていない.
- 詳細
--enable-mbstring
mb_strlen()
mb_strpos()
mb_strrpos
mb_substr()
--enable-mbregex
mb_ereg()
mb_eregi()
mb_ereg_replace()
mb_eregi_replace()
mb_split
- 現行の PHP4.3.3-1 の Debianパッケージのマルチバイト対応状況
--enable-mbstring のみ付いている為,mb_str* しか使用できない.
--enable-mbregex 付きで再コンパイルするしかない.
- Reference
[PHP-users 13906] Re: マルチバイト対応:mb_eregの未定義エラーについて
http://ns1.php.gr.jp/pipermail/php-users/2003-March/014438.html
2003-09-21 Sun
PHP の mysql_connect() で Call to undefined function
- Summary
Call to undefined function: mysql_connect()
というエラーが発生する.
- 原因
/etc/php/apache/php.ini
;extension=mysql.so
extension=mysql.so が コメントアウトされていた.
- 対処法
/etc/php/apache/php.ini を
extension=mysql.so
と変更して
# apachectl stop
# apachectl start
で apache 再起動
2003-09-08 Mon
input type="checkbox"
- ダメサンプル
<form method="GET" action="region.php"> <input type="checkbox" name="region_code" value="01" /> <input type="checkbox" name="region_code" value="02" /> <input type="checkbox" name="region_code" value="03" /> </form>
- $region_code という配列に入って欲しいのに入らない.
最後の値が上書きされる.
- 良いサンプル
<form method="GET" action="region.php"> <input type="checkbox" name="region_code[]" value="01" /> <input type="checkbox" name="region_code[]" value="02" /> <input type="checkbox" name="region_code[]" value="03" /> </form>
- $region_code という配列に入ってくれる.
name="hoge[]"
がミソ
- Reference
[PHP-jp 2755] Re: Form のCHECKBOXの値について
http://www.nishimoto-site.net/archiver/ML/php-ML/199912/msg00134.html