memo.xight.org

Home > Changelogメモ > PHP > 1ページ目 (全9ページ)
ChangeLog 最新ページ / カテゴリ最新ページ / 1 2 3 4 5 6 7 8 9 次ページ / 1ページ目 (全9ページ)
2008-02 / 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29

2008-02-12 Tue

MobilePictogramConverter - PHPの絵文字変換ライブラリ

- Reference
MobilePictogramConverter 絵文字変換ライブラリ
http://php-develop.org/MobilePictogramConverter/

PHPとか (開発者のblog)
http://d.hatena.ne.jp/ryster/

カテゴリ: [PHP][Mobile]

2007-03-19 Mon

symfony 関連

- Reference
symfony Web PHP framework
http://www.symfony-project.com/

CodeZine - symfony入門: symfonyで始めるPHPフレームワーク
http://codezine.jp/a/article/aid/704.aspx

FrontPage - Symfony.jp Symfonyの日本語情報
http://symfony.jp/

カテゴリ: [PHP][Stub]

2007-02-14 Wed

PHPの文字化け - 5つの誤解と5つの対策

- Summary
設定すべき項目は以下.

;; Disable Output Buffering
output_buffering = Off

;; Set HTTP header charset
; default_charset = EUC-JP

;; Set default language to Japanese
mbstring.language = Japanese

;; HTTP input encoding translation is enabled.
mbstring.encoding_translation = off

;; Set HTTP input encoding conversion to auto
mbstring.http_input = pass

;; Convert HTTP output to EUC-JP
mbstring.http_output = pass

;; Set internal encoding to EUC-JP
mbstring.internal_encoding = EUC-JP

;; Do not print invalid characters
mbstring.substitute_character = none

mbstring.detect_order = SJIS,EUC-JP,JIS,UTF-8,ASCII



- 誤解1: default_charsetはデフォルトの文字コードのことではない.
default_charsetは,出力時にHTTPヘッダとして送信する文字コード名のこと.

default_mimetype = 'text/html'
default_charset = 'utf-8' の場合

header('Content-Type: text/html; charset:utf-8');

が自動的に実行される.

Content-Typeが固定されるため,default_charsetは使用すべきではない.

- 誤解2: languageパラメータは内部言語のことではない.
languageパラメータは,mb_send_mailを利用した際にのみ使用される.
また,mb_send_mailは文字コードの変換を指定できないため,使用すべきでない.
で代替可能.
よって,languageパラメータは実質的に意味をなさない.

- 誤解3: internal_encodingは内部エンコードのことではない.
internal_encodingはmbstring関数のデフォルトエンコードのこと.
mb_convert_kanaなどで変換元文字コードの指定がない場合に使用される.

変換元文字コードを固定にするため,
internal_encodingはソースコードの文字コードと揃えておくと良い.

- 誤解4: http_outputを指定しても,自動的に文字コードは変換されない.
http_outputとは,mb_output_handlerが実行された時の出力エンコード.
ob_start("mb_output_handler")

でと指定して初めて使われる.
また,http_outputの動作条件は,出力がtext/htmlである必要がある.

- 誤解5: detect_orderでautoを指定してはいけない.
detect_orderとは,文字コードの自動検出の優先順位のこと.
未指定の場合は,"auto" という値になるが,
"auto" は "ASCII,JIS,UTF-8,EUC-JP,SJIS" に展開される.

マルチバイトを扱う際に,ASCIIが最初にある点が問題.
出力する文字コードを先頭にし,JISやASCIIは最後の方に設定する.

- 結論
対策1: default_charsetを設定しない.
対策2: mb_send_mailを使用しない.
対策3: internal_encodingをソースコードの文字コードと揃える.
対策4: http_outputを使用しない.
対策5: detect_orderは必ず指定する.

- Reference
PHPの文字化けを本気で解決する - ぎじゅっやさん
http://hain.jp/index.php/tech-j/2007/02/13/%EF%BC%B0%EF%BC%A8%EF%BC%B0%E3%81%AE%E6%96%87%E5%AD%97%E5%8C%96%E3%81%91

カテゴリ: [PHP]

2007-01-29 Mon

PHPで画像にWatermark 加工

- Summary
二つの画像を合成し,Watermark加工が行なえる.

- Source

function emboss($pic1,$patt) {
	header("Content-type: image/png");
	
	$source=imagecreatefromjpeg($pic1);    // Source
	$pattern=imagecreatefromjpeg($patt);    // pattern
	list($width, $height) = getimagesize($pic1);
	list($widthpatt, $heightpatt) = getimagesize($patt);
	$new_width=$width;
	$new_height=$width/$widthpatt*$heightpatt;
	if($new_height>$height){
		$offset=intval(($new_height-$height)/2);
	}
	elseif($new_height<$height){
		$offset=intval(($new_height-$height)/2);
	}
	else{
		$offset=0;
	}
	
	$image_p = imagecreatetruecolor($new_width, $new_height);
	$pattern = imagecreatefromjpeg($patt);
	imagecopyresampled($image_p, $pattern, 0, 0, 0, 0, $new_width, $new_height, $widthpatt, $heightpatt);
	
	$im = imagecreatetruecolor($width, $height);   
	
	for($y=0; $y < $height; $y++) {
		for($x=0; $x < $width; $x++) {
			$colors=imagecolorsforindex($source, imagecolorat($source, $x,$y));
			$pattern_color=imagecolorsforindex($image_p, imagecolorat($image_p, $x,($y+$offset)));
			//changes brightness depending on luminance
			if(($y+$offset+1)>0 &&($y+$offset)<($new_height-1)){
				$brightness=abs(($pattern_color['red']*50/255)-50);
				if($pattern_color['red']<150){
					$change=true;}
				else{
					$change=false;
					$tally=0;
				}
				if($change&&$tally<2){
					$highlight=1.8;
					$tally++;
				}
				else{
					$highlight=1;
				}
				$brightness = $brightness * $highlight;
			}
			else{
				$brightness=0;
			}
			$r=(($colors['red']+$brightness)>255)? 255 : ($colors['red']+$brightness);
			$g=(($colors['green']+$brightness)>255)? 255 : ($colors['green']+$brightness);
			$b=(($colors['blue']+$brightness)>255)? 255 : ($colors['blue']+$brightness);
			
			$test=imagecolorallocate($im, $r,$g,$b);
			imagesetpixel($im,$x, $y, $test);
		}
	}
	imagepng($im);
	imagedestroy($im);
}
emboss("me.jpg","patternsq.jpg");
//emboss("magic800.jpg","patternsq.jpg");
//emboss("crop.jpg","patternsq.jpg");


<img src="emboss.php" />


- Reference
http://www.ckdog.co.uk/php/imgtests/emboss.phps

Watermarking JPEG and PNG Images with PHP and GD2
http://koivi.com/php-gd-image-watermark/

- via
Merge images / add logo - PHP
http://www.thescripts.com/forum/thread121386.html

カテゴリ: [PHP]

2006-12-02 Sat

PHPでオーディオ読み上げCAPTCHAを実現

- Summary

function joinwavs($wavs){
    $fields = join('/',array( 'H8ChunkID', 'VChunkSize', 'H8Format',
        'H8Subchunk1ID', 'VSubchunk1Size',
        'vAudioFormat', 'vNumChannels', 'VSampleRate',
        'VByteRate', 'vBlockAlign', 'vBitsPerSample' ));
    $data = '';
    foreach($wavs as $wav){
        $fp     = fopen($wav,'rb');
        $header = fread($fp,36);
        $info   = unpack($fields,$header);
        // read optional extra stuff
        if($info['Subchunk1Size'] > 16){
            $header .= fread($fp,($info['Subchunk1Size']-16));
        }
        // read SubChunk2ID
        $header .= fread($fp,4);
        // read Subchunk2Size
        $size  = unpack('vsize',fread($fp, 4));
        $size  = $size['size'];
        // read data
        $data .= fread($fp,$size);
    }
    return $header.pack('V',strlen($data)).$data;
}


- Usage
joinwavs(array("1st.wav","2nd.wav","3rd.wav"));


- Reference
splitbrain.org - Joining .WAVs with PHP
http://www.splitbrain.org/blog/2006-11/15-joining_wavs_with_php

Index of /audio
http://bartok.wizbit.net/audio/

- via
phpspot開発日誌 - 2006-12-01 - PHPでオーディオ読み上げCAPTCHAを実現する方法
http://phpspot.org/blog/archives/2006/12/phpcaptcha_1.html

カテゴリ: [PHP]

2006-12-01 Fri

PHPのregister_globalsをoffにする

- Summary
register_globals = on 前提のプログラムを,
register_globals = off にするための方法.

- Reference
PHPのregister_globalsをoffにする
http://cgi36.plala.or.jp/tera5/v/security/register_globals1/chap01.html

カテゴリ: [PHP]

2006-11-30 Thu

PhpUnit - PHPのユニットテスト自動化ツール

- Reference
SourceForge.net: PhpUnit
http://sourceforge.net/projects/phpunit/

PHPUnit
http://www.go-pear.org/manual/ja/html/package.php.phpunit.html

Do You PHP? - PhpUnit - 最強のユニットテスト自動化ツール
http://www.doyouphp.jp/tips/tips_phpunit.shtml

PEAR hacks - PHPUnitの使い方
http://www.aglabo.com/agl/proevo/PHP/PEAR/phpunit-howto.html

PhotoCabi-diary - 2004-11-18 - PHPUnitの使い方
http://www.photocabi.net/mt/archives/000049.html

カテゴリ: [PHP]

2006-11-30 Thu

Smarty chalowプラグイン

- Source

### Smarty
# usage: {{smarty('検索語')}}
sub smarty {
	my ($str) = @_;
	my $prefix = 'http://smarty.php.net/manual/en/search.php?query=';
	my $enc = url_encode($str);
	return qq(<a href="$prefix$enc">$str</a>);
}

- Reference
http://smarty.php.net/manual/en/search.php?query=keyword

カテゴリ: [PHP][chalow]

2006-11-30 Thu

Smartyを使った開発でデバッグを行う方法

- Summary
Smartyを使った開発でデバッグを行う方法.

- 常にデバッギングコンソールをポップアップ表示

$smarty->debugging = true;


- 常にデバッギングコンソールをHTML内に表示
$smarty->debugging = true;
$smarty->assign('_smarty_debug_output', 'html');


- URL に SMARTY_DEBUG が含まれる場合にデバッギングコンソールを表示
$smarty->debugging_ctrl = 'URL';


- テンプレート変数 debug を利用してポップアップ表示


- テンプレート変数 debug を利用してHTML内に表示
{debug output='html'}


- debug_print_var 修正子を利用して,割り当てられた変数を表示
{$foo|@debug_print_var}


- debug_print_var 修正子を利用して,割り当てられた変数を表示
インデント1単位,100文字まで表示.
インデント1単位は半角スペース2文字分.
{$foo|@debug_print_var:2:100}


- Reference
cl.pocari.org - Smarty を使った開発でデバッグを行う 4 つの方法
http://cl.pocari.org/2006-11-29-1.html

Smarty - $debugging
http://smarty.php.net/manual/en/variable.debugging.php

Smarty - $debugging_ctrl
http://smarty.php.net/manual/en/variable.debugging.ctrl.php

Smarty - {debug}
http://smarty.php.net/manual/en/language.function.debug.php

$debugging
$debugging_ctrl
{debug}

カテゴリ: [PHP]

2006-11-25 Sat

PHPUnit 3.0

- Reference
Sooey - 2006-11-20 - PHPUnit 3.0リリース
http://www.sooey.com/journal/2006/11/20/633/

PHPUnit ポケットガイド
http://www.phpunit.de/pocket_guide/3.0/ja/

- via
オレンジニュース - 2006-11-21
http://secure.ddo.jp/~kaku/tdiary/20061121.html#p02

カテゴリ: [PHP]

2006-11-24 Fri

ZendFrameworkでAjaxを使ったチャットシステムを作るチュートリアル

- Reference
Zend Developer Zone | AJAX Chat Tutorial
http://devzone.zend.com/node/view/id/1234

- via
phpspot開発日誌 - ZendFrameworkでAjaxを使ったチャットシステムを作るチュートリアル
http://phpspot.org/blog/archives/2006/11/zendframeworkaj.html

カテゴリ: [PHP][Ajax]

2006-11-24 Fri

PearのServices_JSONを使ってPHPの変数を簡単にJSON形式にする

- Summary
日本語を使う場合はUTF-8の変数を渡す必要がある.

require_once('Services/JSON.php');
 
$json = new Services_JSON();
$obj = array(
    'id'   => array(
       'foo',
       'bar',
       array('aa' => 'bb')
       ),
       'foobar' => $string,
       'a'   => 123 ,
       'b'   => true
);
$js = $json->encode($obj);
echo $js;


- Reference
phpspot開発日誌 - PearのServices_JSONを使ってPHPの変数を簡単にJSON形式にするサンプル
http://phpspot.org/blog/archives/2006/11/pearservices_js.html

カテゴリ: [PHP]

2006-11-24 Fri

AjaxCore - Ajax アプリ開発用 PHPフレームワーク

- Reference
SourceForge.net: ajaxcore
http://sourceforge.net/projects/ajaxcore/

Ajaxian - AjaxCore: PHP Ajax Framework
http://ajaxian.com/archives/ajaxcore-php-ajax-framework

- via
PHPプロ! - Ajax アプリ開発用 PHPフレームワーク「AjaxCore」
http://www.phppro.jp/news/238

カテゴリ: [PHP][Ajax]

2006-11-21 Tue

PHPで使えるCAPTCHA画像作成ライブラリ

- Reference
phpspot開発日誌 - 2006-11-20 - PHPで使えるCAPTCHA画像作成ライブラリまとめ
http://phpspot.org/blog/archives/2006/11/phpcaptcha.html

カテゴリ: [PHP]

2006-11-21 Tue

12のPHP最適化テクニック

- Summary
 1. staticメソッドが使えるなら使おう.速度は4倍になる
 2. __get, __set, __autoload は使わない
 3. require_once は重い
 4. include, requireで読み込むファイルはフルパスにしよう
 5. スクリプト開始時のUNIXタイムを $_SERVER['REQUEST_TIME'] で取れる
 6. strncasecmp関数やstrpbrk関数を使えるケースはこれらを使い,正規表現は使わない
 7. preg_replaceはstr_replaceより速い,しかし,strtrはpreg_replaceより4倍速い
 8. 引数を,単体か配列かで自動判別するようなコードは出来るだけ避ける
 9. @ を使ったエラー制御はとても遅い.→ @fputs($fp, "?");
10. $row["id"] は $row[id] より7倍速い.
11. PHPのエラーメッセージは重い. (noticeとかwarningとか)
12. for ($x=0; $x < count($array); $x) のように,
    forの中でcountを使うと毎回countが呼ばれるので使わない.
- Reference
12 PHP optimization tips
http://www.moskalyuk.com/blog/php-optimization-tips/1272

- via
phpspot開発日誌 - 2006-11-21 - 12のPHP最適化テクニック
http://phpspot.org/blog/archives/2006/11/12php.html

カテゴリ: [PHP]

2006-11-21 Tue

phpMyEdit - データベースのメンテナンス画面を生成

- Summary
phpMyEditSetup.phpにアクセスしウィザード形式で進んでいくと,
最終的に指定したテーブルの操作用ライブラリが出来上がる.

- Reference
phpMyEdit: Instant MySQL Table Editor and PHP Code Generator
http://www.phpmyedit.org/

- via
phpspot開発日誌 - 2005-11-07 - phpMyEdit: DB操作コード自動生成
http://phpspot.org/blog/archives/2005/11/phpmyedit_welco.html

MOONGIFT - phpMyEdit - データベースのメンテナンス画面を生成
http://oss.moongift.jp/intro/i-2816.html

MOONGIFT - phpMyEdit レビュー
http://oss.moongift.jp/review/i-2817.html

カテゴリ: [PHP][MySQL]

2006-09-07 Thu

Services_Delicious - del.icio.usのAPIを利用するためのPearパッケージ

- Summary
del.icio.usのAPIを利用するためのPearパッケージ.
[2006-08-09] より del.icio.us のAPIがHTTPSのみを受け付けるようになった.

- Reference
p4lifeのメモ - 2006-09-02 - PEAR::Services_Delicious 0.5.0 をリリースしました
http://d.hatena.ne.jp/p4life/20060902/1157210163



phpspot開発日誌 - 2006-08-21 - 新しくなったdel.icio.usのAPI仕様と投稿サンプルプログラム
http://phpspot.org/blog/archives/2006/08/deliciousapi.html

del.icio.us/help/api
http://del.icio.us/help/api/

del.icio.us - blog - 2006-08-06 security (everybody feels better with)
http://blog.del.icio.us/blog/2006/08/security_everyb.html

Yahoo! API News - 2006-08-15 - del.icio.us and Answers (by Jeremy Zawodny)
http://jeremy.zawodny.com/blog/archives/007202.html

- via
phpspot開発日誌 - 2006-09-06 - del.icio.usのAPIを叩くPearパッケージ『Services_Delicious』がアップデート
http://phpspot.org/blog/archives/2006/09/deliciousapipea.html

カテゴリ: [PHP][PEAR]

2006-09-04 Mon

PEAR::Contact_AddressBook - アドレス帳のインポート,エクスポートを可能にするPEARパッケージ

- 対応するアドレス帳
Eudora
KMail (KDE Mailer) CSV
Mozilla/Thunderbird/Netscape CSV
Microsoft Outlook CSV
Microsoft Windows Address Book (WAB)/Outlook Express CSV
Palm Pilot CSV
Yahoo! Mail Address Book
Gmail Address Book

- Reference
Contact_AddressBook

- via
phpspot開発日誌 - 2006-09-04 - アドレスブックのインポート/エクスポートを可能にする『PEAR::Contact_AddressBook』
http://phpspot.org/blog/archives/2006/09/pearcontact_add.html

カテゴリ: [PHP]

2006-08-26 Sat

PHPで安全なセッション管理を実現する方法

- Reference
いしなお! - 2006-08-25 - PHPで安全なセッション管理を実現する方法
http://tdiary.ishinao.net/20060825.html#p02

カテゴリ: [PHP][Security]
2008-02 / 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
最終更新時間: 2008-02-20 21:23

Color Reference

ChangeLogを検索
携帯電話からアクセス!

カテゴリ

最近の話題

リンク

過去ログ

Google

QR Code

Since
2002-11-28
Update
2008-02-20 21:23
Copyright © 2005 xight.org All Rights Reserved.