<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
		xmlns:xhtml="http://www.w3.org/1999/xhtml"
>

<channel>
	<title>乱雑モックアップ &#187; php</title>
	<atom:link href="http://blog.sakurachiro.com/category/script/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.sakurachiro.com</link>
	<description>らんざつ[乱雑] （名・形動）[文]ナリ 入り乱れていること。乱れていて秩序がないこと。また、そのさま。</description>
	<lastBuildDate>Fri, 02 Dec 2011 20:09:59 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://blog.sakurachiro.com/category/script/php/feed/" />
		<item>
		<title>phpでサーバーのフルパスを調べる</title>
		<link>http://blog.sakurachiro.com/2011/09/php-fullpath/</link>
		<comments>http://blog.sakurachiro.com/2011/09/php-fullpath/#comments</comments>
		<pubDate>Sun, 18 Sep 2011 12:36:43 +0000</pubDate>
		<dc:creator>まこと</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[ベーシック認証]]></category>

		<guid isPermaLink="false">http://blog.sakurachiro.com/?p=2553</guid>
		<description><![CDATA[ベーシック認証をかけたい時に サーバーのフルパスが分からなくて困る人間なのでメモ ちなみに、以下のページで.htaccessと.htpasswdを簡単に作れる。 .htaccess ファイルを簡単作成「.htaccess [...]]]></description>
			<content:encoded><![CDATA[<pre class="brush: php; class-name: php-sh; title: ; notranslate">&lt;?php
echo __FILE__;
?&gt;
</pre>
<p>ベーシック認証をかけたい時に<br />
サーバーのフルパスが分からなくて困る人間なのでメモ</p>
<p>ちなみに、以下のページで.htaccessと.htpasswdを簡単に作れる。<br />
<a href="http://www.htaccesseditor.com/#a_basic">.htaccess ファイルを簡単作成「.htaccess Editor」</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.sakurachiro.com/2011/09/php-fullpath/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://blog.sakurachiro.com/2011/09/php-fullpath/" />
	</item>
		<item>
		<title>concrete5をxampp環境にインストール</title>
		<link>http://blog.sakurachiro.com/2011/06/concrete5-xampp/</link>
		<comments>http://blog.sakurachiro.com/2011/06/concrete5-xampp/#comments</comments>
		<pubDate>Tue, 21 Jun 2011 19:17:33 +0000</pubDate>
		<dc:creator>まこと</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[xampp]]></category>
		<category><![CDATA[CMS]]></category>
		<category><![CDATA[concrete5]]></category>
		<category><![CDATA[session.save_path]]></category>

		<guid isPermaLink="false">http://blog.sakurachiro.com/?p=2520</guid>
		<description><![CDATA[concrete5(コンクリートファイブ)というCMSがあるそうです。 concrete5日本語公式サイト by Usagi Project 何がいいのかイマイチ判らないまま仕事で使う事になったので とりあえず動作確認用 [...]]]></description>
			<content:encoded><![CDATA[<p>concrete5(コンクリートファイブ)というCMSがあるそうです。<br />
<a href="http://concrete5-japan.org/">concrete5日本語公式サイト by Usagi Project</a></p>
<p>何がいいのかイマイチ判らないまま仕事で使う事になったので<br />
とりあえず動作確認用にローカルにインストールしてみようとしたら<br />
Warning: session_start()ってエラーがでて<br />
上手くインストール出来なかったよっていうメモ。</p>
<h3>環境</h3>
<p>windows7 64bit<br />
<a href="http://sourceforge.net/projects/xampp/files/">xampp1.7.3</a><br />
<a href="http://concrete5-japan.org/download/">concrete5.4.1.1.1 日本語 最新安定板</a></p>
<h3>インストールの準備</h3>
<p>以下のリンクを参考にphpMyAdminからconcrete5用の空DBを作成<br />
バーチャルホストも用意しておく<br />
うちは_c.localhostにした。</p>
<p><a href="http://blog.kyosuke.jp/2008/11/18/62">inputlog &#8211; Concrete5をxamppにインストール</a><br />
<a href="http://concrete5-japan.org/help/install/gettingready/">インストール準備 :: concrete5日本語公式サイト</a></p>
<h3>インストール</h3>
<p>_c.localhostにアクセスすると下のようなエラーが表示されて先に勧めなかった。</p>
<pre class="brush: plain; title: ; notranslate">Warning: session_start() [function.session-start]: open(\xampp\tmp\sess_jpft2igj399p07rk0ecstj7tn5, O_RDWR) failed: No such file or directory (2) in D:\_webroot\c5\htdocs\concrete\startup\session.php on line 18</pre>
<p><a href="http://blog.sakurachiro.com/wp-content/uploads/2011/06/20110621_2.png" rel="shadowbox[sbpost-2520];player=img;" title="Warning: session_start() [function.session-start]: open"><img src="http://blog.sakurachiro.com/wp-content/uploads/2011/06/20110621_2-435x480.png" alt="[image]Warning: session_start() [function.session-start]: open" title="Warning: session_start() [function.session-start]: open" width="435" height="480" class="alignnone size-large wp-image-2521" /></a></p>
<h3>エラーの原因</h3>
<p>どうも、php.iniのsession.save_pathがおかしいみたい。</p>
<pre><code>C:\xampp\php\php.ini</code></pre>
<p>を開いて、1496行目あたりの</p>
<pre><code>session.save_path = "\xampp\tmp"</code></pre>
<p>を<br />
こんな感じに修正</p>
<pre><code>session.save_path="C:/xampp/tmp"</code></pre>
<p>xamppのコントロールパネルからapacheを再起動して<br />
_c.localhostにアクセスしてみるとエラーが消えた。</p>
<p><a href="http://blog.sakurachiro.com/wp-content/uploads/2011/06/20110622_1.png" rel="shadowbox[sbpost-2520];player=img;" title="エラーが消えた"><img src="http://blog.sakurachiro.com/wp-content/uploads/2011/06/20110622_1-444x480.png" alt="[image]エラーが消えた" title="エラーが消えた" width="444" height="480" class="alignnone size-large wp-image-2522" /></a></p>
<p>変な達成感があるけど、実際まだ始まってすらいない。</p>
<p>MySQLのサーバーアドレスは<br />
デフォルトだとlocalhostで<br />
その下はMySQLにログインする時のidとpass<br />
データベース名はインストールの準備で作ったヤツ</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.sakurachiro.com/2011/06/concrete5-xampp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://blog.sakurachiro.com/2011/06/concrete5-xampp/" />
	</item>
		<item>
		<title>windows7 64bitにxamppを再インストール</title>
		<link>http://blog.sakurachiro.com/2011/06/windows7-64bit-xampp/</link>
		<comments>http://blog.sakurachiro.com/2011/06/windows7-64bit-xampp/#comments</comments>
		<pubDate>Mon, 20 Jun 2011 18:15:36 +0000</pubDate>
		<dc:creator>まこと</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[xampp]]></category>
		<category><![CDATA[とりあえずメモ]]></category>
		<category><![CDATA[ssi]]></category>
		<category><![CDATA[Virtual Host]]></category>

		<guid isPermaLink="false">http://blog.sakurachiro.com/?p=2519</guid>
		<description><![CDATA[mysqlのrootパスワード忘れて再インストールした際のやったことメモ。 なんか足りてない気がする。 ダウンロード 旧バージョン(1.7.2)をインストールしたかったので こっちから拾ってきた XAMPP &#8211 [...]]]></description>
			<content:encoded><![CDATA[<p>mysqlのrootパスワード忘れて再インストールした際のやったことメモ。<br />
なんか足りてない気がする。</p>
<h3>ダウンロード</h3>
<p>旧バージョン(1.7.2)をインストールしたかったので<br />
こっちから拾ってきた<br />
<a href="http://sourceforge.net/projects/xampp/files/XAMPP%20Windows/">XAMPP &#8211; Browse /XAMPP Windows at SourceForge.net</a></p>
<p>最新版はこっちにも。<a href="http://www.apachefriends.org/jp/xampp-windows.html">apache friends &#8211; xampp for windows</a></p>
<h3>インストール</h3>
<p>全部デフォルトでポチポチしてって完了。<br />
(※インストール先をc:にすると勝手にxamppフォルダが出来て、c:\xamppにインストールされた。</p>
<h3>設定</h3>
<p>localhostにアクセスして<br />
左側のメニューの<br />
セキュリティ &#8211; セキュリティから</p>
<p>そのような問題をすべて修正するには、単純に次のツールを使ってください。<br />
=> http://localhost/security/xamppsecurity.php <=</p>
<p>をクリックして<br />
パスワードを設定。</p>
<p>パスワード指定時にチェックをいれとかないと<br />
mysqlrootpasswd.txt や<br />
xamppdirpasswd.txt が生成されないみたい。</p>
<p><a href="http://blog.sakurachiro.com/wp-content/uploads/2009/09/20110621_1.png" rel="shadowbox[sbpost-2519];player=img;" title="セキュリティ"><img src="http://blog.sakurachiro.com/wp-content/uploads/2009/09/20110621_1-463x480.png" alt="[image]セキュリティ" title="セキュリティ" width="463" height="480" class="alignnone size-large wp-image-2517" /></a></p>
<h4>.htaccessをC:\xampp\htdocs か C:\xampp\htdocs\xamppあたりに置くらしいけど</h4>
<pre><code>
Order deny,allow
Deny from All
Allow from localhost 127.0.0.1
</code></pre>
<p>や</p>
<pre><code>
order deny,allow
deny from all
allow from localhost
allow from 127.0.0.1
</code></pre>
<p>みたいなの。<br />
大文字と小文字に違いはあるのかな？</p>
<p>localhostが開かなくなった、なんか間違ってたんだろうか。</p>
<p>あとSSIとバーチャルホスト(バーチャルドメイン？)の設定した。<br />
<a href="http://blog.sakurachiro.com/2011/04/xampp-include-ssi/">xamppでinclude(SSI)を使えるようにする</a><br />
<a href="http://blog.sakurachiro.com/2010/10/site-root-relative-paths-dreamweavr-virtual-domain/">ルートパスとDreamweaverとバーチャルホスト(バーチャルドメイン？)</a></p>
<p>httpd-vhosts.conf<br />
19行目あたりの<br />
<span class="note2">#NameVirtualHost *:80</span>のコメントアウトを解除して<br />
すぐ下に</p>
<pre><code>
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs"
ServerName localhost
</VirtualHost>
</code></pre>
<p>を追加した。</p>
<p>(※なぜかlocalhostじゃないやつがlocalhostで開いてしまったので</p>
<h3>php.ini</h3>
<p>C:\xampp\php\php.ini<br />
を開いて、mbstringで検索</p>
<p>1771行あたりから始まるmbstringの<br />
;mbstring.language = Japanese<br />
みたいなやつの先頭の「;(セミコロン)」を削除した</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.sakurachiro.com/2011/06/windows7-64bit-xampp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://blog.sakurachiro.com/2011/06/windows7-64bit-xampp/" />
	</item>
		<item>
		<title>さくらインターネットのスタンダードプランでphp5.3.3をインストールして使う</title>
		<link>http://blog.sakurachiro.com/2010/08/sakura-std-php533/</link>
		<comments>http://blog.sakurachiro.com/2010/08/sakura-std-php533/#comments</comments>
		<pubDate>Fri, 13 Aug 2010 18:59:08 +0000</pubDate>
		<dc:creator>まこと</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[さくらちろ]]></category>

		<guid isPermaLink="false">http://blog.sakurachiro.com/?p=2056</guid>
		<description><![CDATA[使用したSSHクライアント / index &#8211; Terminal Emulator Poderosa (さくらインターネットの公式で例に挙げられていたので使った、秘密鍵というのを何度チャレンジしても作れなくて [...]]]></description>
			<content:encoded><![CDATA[<p>使用したSSHクライアント / <a href="http://ja.poderosa.org/">index &#8211; Terminal Emulator Poderosa</a><br />
(さくらインターネットの公式で例に挙げられていたので使った、秘密鍵というのを何度チャレンジしても作れなくてログインが面倒くさい)</p>
<h3>このサイトを参考にしてインストールしました。</h3>
<p><a href="http://d.hatena.ne.jp/kanreisa/20091105/1257422017" class="broken_link">さくらのレンタルサーバーで、php5-mysqli をつかえるようにする覚書。(PHP5.3.0をコンパイルして使う) &#8211; れいさ屋</a></p>
<p>上記サイトに書いてある順番そのまんま入力していくだけでphp5.3.3のインストールに成功した(<em>※コンパイル時のコマンドでmysqlに関係するところを省略したけど</em>)。<br />
サイトが移転したようなので、消えないと思うけど念のため記事を一部引用させていただきます。</p>
<p><em>※php-5.3.0をphp-5.3.3に変更して使った</em></p>
<blockquote><p>作業ディレクトリの作成</p>
<p>mkdir tmp<br />
cd tmp</p>
<p>PHPをダウンロード・解凍</p>
<p><code>wget http://jp.php.net/get/php-5.3.0.tar.gz/from/this/mirror<br />
	tar zxvf php-5.3.0.tar.gz</code></p>
<p>    * TABキーによる補完が利用できます</p>
<p>コンパイル</p>
<p><code>cd php-5.3.0<br />
	./configure --prefix=/home/<username> --with-config-file-path=/home/<username>/www/ --enable-force-cgi-redirect --enable-mbstring --enable-mbregex --enable-calendar --enable-pdo --with-pcre-dir=/usr/local --with-openssl=/usr --with-iconv=/usr/local --with-gd --with-zlib=/usr --with-jpeg-dir=/usr/local --with-png-dir=/usr/local --with-ttf --with-freetype-dir=/usr/local --with-mysql=/usr/local/mysql/5.1 --with-pdo-mysql=/usr/local/mysql/5.1 --with-mysqli=/usr/local/mysql/5.1/bin/mysql_config --enable-soap --with-curl --with-xsl=/usr/local --enable-dom --with-gettext=/usr/local --enable-exif</code></p>
<p>    * <username>の部分は、書き換えてください。<br />
    * ミソは、&#8211;with-mysqli=/usr/local/mysql/5.1/bin/mysql_config これです。</p>
<p><code>renice +20 -u <username><br />
	make<br />
	make install</code></p>
<p>使って見るには：</p>
<p>このままでは今回コンパイルしたPHPは、使われることはありません。</p>
<p>ドメインごとに、以下の手順をする必要があります。</p>
<p>・例: www.example.com (/home/<username>/www/example.com/)でつかえるようにする場合</p>
<p><code>mkdir /home/<username>/www/example.com/cgi-bin<br />
	cp /home/<username>/bin/php-cgi /home/<username>/www/example.com/cgi-bin/php5.cgi</code></p>
<p>このようにしてphp-cgiをコピーしたら、~/example.com/ディレクトリ上に、.htaccessを作成します。</p>
<p>内容は、</p>
<p><code>Action php5-script /cgi-bin/php5.cgi<br />
	AddHandler php5-script .php .php5</code></p>
<p>こんな感じにします。すると、.php拡張子にアクセスを試みた場合、/cgi-bin/php5.cgiでphpコードが実行されるわけです。ちなみに、デフォルトでmysqliは有効になっています。特に設定は弄る必要ないです。<br />
(推奨)php.iniの設定</p>
<p><code>mbstring.language = Japanese<br />
	mbstring.internal_encoding = UTF-8<br />
	mbstring.http_input = auto<br />
	;mbstring.http_output = UTF-8<br />
	mbstring.detect_order = auto</p>
<p>	date.timezone = Asia/Tokyo</code></p>
<p>コイツは、.htaccessと同じディレクトリに設置しましょう。<br />
おわりに</p>
<p>    * mysqliに限らず、その他組み込まれていないモジュールについても、この方法でつかえるようにすることができます。詳しくは、<a href="http://www.php.net/">php公式サイト</a>あたりをご覧ください。
</p></blockquote>
<p>php.iniの設定の<span class="note2">date.timezone = Asia/Tokyo</span>、これ大事ぽかった。</p>
<h3>なんでphp5.3.3をインストールしたかったか、事の経緯</h3>
<p>iPhoneのユーザー辞書用にファイルを変換するサイト(<a href="http://sakurachiro.com/data/ios4-userwords-diy/">ココ</a>とか<a href="http://sakurachiro.com/data/ios4-userwords/">ここ</a>とか)はphpで作ってて、sqliteをいじったり作成したりするのにPDOクラス(php5.1以降で対応)やらSQLite3クラス(php5.3以降で対応)やらを使ってる。</p>
<p>動作テストはローカルの<a href="http://www.apachefriends.org/jp/xampp-windows.html">xampp</a>でやってた(phpのバージョンは5.3.1みたい)。<br />
なのでPDOクラスもSQLite3クラスも問題なく使えてた。</p>
<p>だがしかし、残念な事に作成したphpを実際に走らせるこのサーバーのphpは5.2.13(CGI版)だった(<a href="http://www.sakura.ne.jp/rentalserver/standard/">さくらインターネットのスタンダードプラン</a>)。<br />
つまり本サーバーではSQLite3クラスが使えない。</p>
<p>そんな最初に気づいておかなきゃいけない大事な事も気にかけずに、よみと単語の.txtを.sqliteに変換して追加したり作成するphpを作ってローカルでテストして問題なさそうだったので、本サーバーにアップしたらあたりまえのように動かない。</p>
<p>せっかく作ったプログラムがこのままだと使えない。<br />
なのでSQLite3クラスを使えるようにする方法を探す。</p>
<h3>PECLのSQLite3拡張モジュールを使えば大丈夫？</h3>
<p><a href="http://pecl.php.net/package/sqlite3/download/0.6">PECL :: Package :: sqlite3 :: download</a></p>
<p>さくらインターネットのスタンダードプランのサーバーにPECLをインストールさせるには、どうもautoheaderとautoconfを弄らないと使えないみたいなんだけど、うちの頭が悪すぎた為にうまいこと設定が出来ずインストール出来なかった。</p>
<p>参考 / <a href="http://dozo.matrix.jp/pecl/%E3%83%AC%E3%83%B3%E3%82%BF%E3%83%AB%E3%82%B5%E3%83%BC%E3%83%90">さくらインターネットにPECLをインストール [dozo dokuwiki.php]</a></p>
<p>なので、php自体を5.3以上にしてしまえ！と思ったわけです。</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.sakurachiro.com/2010/08/sakura-std-php533/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://blog.sakurachiro.com/2010/08/sakura-std-php533/" />
	</item>
		<item>
		<title>mb_strlen()で変な値が返ってくる時は文字エンコードを指定する。</title>
		<link>http://blog.sakurachiro.com/2010/07/mb_strlen/</link>
		<comments>http://blog.sakurachiro.com/2010/07/mb_strlen/#comments</comments>
		<pubDate>Sun, 18 Jul 2010 14:21:10 +0000</pubDate>
		<dc:creator>まこと</dc:creator>
				<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://blog.sakurachiro.com/?p=2023</guid>
		<description><![CDATA[strlenは文字列の長さを取得する関数で戻り値はバイト数らしい。 そして、mb_strlenはマルチバイトを考慮して文字列の長さを取得できるそうだ。 こんな感じ。 けれど、ローカルのxamppでは以下の値を取得してしま [...]]]></description>
			<content:encoded><![CDATA[<p>strlenは文字列の長さを取得する関数で戻り値はバイト数らしい。<br />
そして、mb_strlenはマルチバイトを考慮して文字列の長さを取得できるそうだ。</p>
<p>こんな感じ。</p>
<pre class="brush: php; title: ; notranslate">print(mb_strlen(&quot;あ&quot;));
//出力 1
print(mb_strlen(&quot;あいう&quot;));
//出力 3</pre>
<p>けれど、ローカルのxamppでは以下の値を取得してしまった。</p>
<pre class="brush: php; title: ; notranslate">print(mb_strlen(&quot;あ&quot;));
//出力 3
print(mb_strlen(&quot;あいう&quot;));
//出力 9</pre>
<p>phpの内部エンコーディングと合わない時にそうなるみたいで、<br />
解決法はmb_strlen()関数の第2引数に文字エンコードを指定すれば良いみたい</p>
<pre class="brush: php; title: ; notranslate">
print(mb_strlen(&quot;あ&quot;,&quot;utf-8&quot;));
//出力 1
</pre>
<p>あーびっくりした。</p>
<p>参考 / <a href="http://itpro.nikkeibp.co.jp/article/COLUMN/20070307/264117/">21. mb_strlen()関数の落とし穴 &#8211; PHP TIPS：ITpro</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.sakurachiro.com/2010/07/mb_strlen/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://blog.sakurachiro.com/2010/07/mb_strlen/" />
	</item>
		<item>
		<title>if文、書き方にバリエーションがあるようだ</title>
		<link>http://blog.sakurachiro.com/2010/05/if/</link>
		<comments>http://blog.sakurachiro.com/2010/05/if/#comments</comments>
		<pubDate>Thu, 13 May 2010 17:28:38 +0000</pubDate>
		<dc:creator>まこと</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[とりあえずメモ]]></category>

		<guid isPermaLink="false">http://blog.sakurachiro.com/?p=1734</guid>
		<description><![CDATA[うちはWordPressもphpも全然初心者であります。 なので思いっきり格好つけて(ソースを書いて)も、周りからみたらきっと恥ずかしい事になってるに違いない。あぁ恥ずかしい。 でもどうせ後で恥をかくなら今恥ずかしい方が [...]]]></description>
			<content:encoded><![CDATA[<p>うちはWordPressもphpも全然初心者であります。<br />
なので思いっきり格好つけて(ソースを書いて)も、周りからみたらきっと恥ずかしい事になってるに違いない。あぁ恥ずかしい。<br />
でもどうせ後で恥をかくなら今恥ずかしい方が良いに決まってる、はしかも若いうちにかかった方がいいって言うし(同じ恥をかく回数がはしかの様に1回ならばの話だけども)。</p>
<p>よし今日も恥をかくことを恐れずに書いていくぞ。と<br />
RADWIMPSの<q>「誤解を恐れず言わせてもらいます」ってそれはもうすでに恐れてます</q>的な前置きでスタートでありんす。</p>
<p><span id="more-1734"></span></p>
<h3>if文</h3>
<p>WordPressのsidebar.phpにdynamic_sidebarの記述があるのだけれど、うちの知っているif文とはちょっと違う書き方のif文になってる。</p>
<pre class="brush: php; title: ; notranslate">&amp;lt;?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar(1) ) : ?&amp;gt;
#ダイナミックサイドバーがあるのでここは出力されない
&amp;lt;?php endif; ?&amp;gt;
#こっちが出力される
1
&amp;lt;?php if ( function_exists('dynamic_sidebar') &amp;amp;&amp;amp; dynamic_sidebar(1) ) : else : ?&amp;gt;
#ダイナミックサイドバーがあるのでここは出力されない
&amp;lt;?php endif; ?&amp;gt;
#こっちが出力される
</pre>
<p>endif;が必要。</p>
<p>うちの知ってるif文</p>
<pre class="brush: php; title: ; notranslate">
&amp;lt;?php
if ( $job ){
print ('(ヽ´ω｀)');
} else {
print ('(；´Д｀)ｳｳｯ…');
}
?&amp;gt;
</pre>
<p>これと同じような意味なのかな</p>
<pre class="brush: php; title: ; notranslate">&amp;lt;?php $job=null; if($job){ ?&amp;gt;
(ヽ´ω｀) //仕事がないので出力されない
&amp;lt;?php }else{ ?&amp;gt;
(；´Д｀)ｳｳｯ… //こっちが出力される
&amp;lt;?php } ?&amp;gt;</pre>
<p>「:」があるうから三項演算子に似てるなーと思ったけどifが最初にないもんねあれは。</p>
<h3>endifで検索したらなんか出てきた</h3>
<p><a href="http://aym.pekori.to/php/migration.if-endif.html">if..endif の文法：PHPマニュアル</a></p>
<h4>elseif/else if</h4>
<p><a href="http://php.net/manual/en/control-structures.elseif.php">PHP: elseif/else if &#8211; Manual</a></p>
<pre class="brush: php; title: ; notranslate">
&amp;lt;?php
//これが
if ($a &amp;gt; $b) {
    echo &amp;quot;a is bigger than b&amp;quot;;
} elseif ($a == $b) {
    echo &amp;quot;a is equal to b&amp;quot;;
} else {
    echo &amp;quot;a is smaller than b&amp;quot;;
}
?&amp;gt;

//こうなる?
if($a &amp;gt; $b):
    echo $a.&amp;quot; is greater than &amp;quot;.$b;
elseif($a == $b): // Note the combination of the words.
    echo $a.&amp;quot; equals &amp;quot;.$b;
else:
    echo $a.&amp;quot; is neither greater than or equal to &amp;quot;.$b;
endif;
?&amp;gt;
</pre>
<p>あー、なんとなくわかってきた<br />
if中に&lt;?php ?&gt;を抜けた時、&lt;?php }else{ ?&gt;だと判りづらいから?</p>
<p>いやしかし:else:ってなんだよ</p>
<h3>dynamic_sidebar()</h3>
<p>ダイナミックサイドバーを出したい時、今はこう書いてたけど</p>
<pre class="brush: php; title: ; notranslate">&amp;lt;?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar(1) ) : ?&amp;gt;
&amp;lt;?php endif; ?&amp;gt;
</pre>
<p>こっちでも出る。大丈夫なのかなこれ。</p>
<pre class="brush: php; title: ; notranslate">&amp;lt;?php dynamic_sidebar(1) ?&amp;gt;</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.sakurachiro.com/2010/05/if/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://blog.sakurachiro.com/2010/05/if/" />
	</item>
		<item>
		<title>自tumblrの画像を表示させるやつ / 編集途中メモ</title>
		<link>http://blog.sakurachiro.com/2010/03/tumblr-xml/</link>
		<comments>http://blog.sakurachiro.com/2010/03/tumblr-xml/#comments</comments>
		<pubDate>Tue, 09 Mar 2010 16:12:25 +0000</pubDate>
		<dc:creator>まこと</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[さくらちろ]]></category>
		<category><![CDATA[tumblr]]></category>

		<guid isPermaLink="false">http://blog.sakurachiro.com/2010/03/%e8%87%aatumblr%e3%81%ae%e7%94%bb%e5%83%8f%e3%82%92%e8%a1%a8%e7%a4%ba%e3%81%95%e3%81%9b%e3%82%8b%e3%82%84%e3%81%a4-%e7%b7%a8%e9%9b%86%e9%80%94%e4%b8%ad%e3%83%a1%e3%83%a2/</guid>
		<description><![CDATA[TumbprAPIのxmlを使って、とりあえずtestデザインのページ下部に設置してみた。 type=photoを50件。 WordPressのshadowbox JSを使っている、が グループ化されてないので連続して表 [...]]]></description>
			<content:encoded><![CDATA[<p>TumbprAPIのxmlを使って、とりあえず<a href="http://blog.sakurachiro.com/2010/03/tumblr-xml/?wptheme=test#tumblrtest">testデザインのページ下部</a>に設置してみた。<br />
type=photoを50件。</p>
<p>WordPressのshadowbox JSを使っている、が<br />
<del datetime="2010-04-23T18:00:54+00:00">グループ化されてないので連続して表示させられてない。</del><br />
ちょっとエッチな画像のreblogが多いので恥ずかしい。</p>
<h3>次の作業</h3>
<p>shadowboxでグループ化<br />
プラグインの管理画面の作り方を調べて作る / 入力するのはidと読み込み件数くらい。</p>
<h3>そのうちやる</h3>
<p><del datetime="2010-04-23T18:00:54+00:00">記事の詳細画面に入った時のnextボタンをアンカーから次の記事へのリンクになるようにしたいなぁ。</del></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.sakurachiro.com/2010/03/tumblr-xml/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://blog.sakurachiro.com/2010/03/tumblr-xml/" />
	</item>
		<item>
		<title>simplexml_load_fileでxmlの要素にアクセス出来なかった。</title>
		<link>http://blog.sakurachiro.com/2010/03/simplexml_load_file/</link>
		<comments>http://blog.sakurachiro.com/2010/03/simplexml_load_file/#comments</comments>
		<pubDate>Fri, 05 Mar 2010 16:20:05 +0000</pubDate>
		<dc:creator>まこと</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[simplexml]]></category>
		<category><![CDATA[tumblr]]></category>

		<guid isPermaLink="false">http://blog.sakurachiro.com/2010/03/simplexml_load_file%e3%81%a7xml%e3%81%ae%e8%a6%81%e7%b4%a0%e3%81%ab%e3%82%a2%e3%82%af%e3%82%bb%e3%82%b9%e5%87%ba%e6%9d%a5%e3%81%aa%e3%81%8b%e3%81%a3%e3%81%9f%e3%80%82/</guid>
		<description><![CDATA[tumblrのxmlを読み込んで画像を表示しようと思ったので simplexmlでxmlを読みこむが何故だか画像urlの要素にアクセス出来ない。 (結論を先に見る) tumblr APIの説明｜和訳 http://(yo [...]]]></description>
			<content:encoded><![CDATA[<p>tumblrのxmlを読み込んで画像を表示しようと思ったので</p>
<h3>simplexmlでxmlを読みこむが何故だか画像urlの要素にアクセス出来ない。</h3>
<p>(<a href="#simplexml_conclusion">結論を先に見る</a>)</p>
<p><a href="http://www.tumblr.com/docs/en/api">tumblr APIの説明</a>｜<a href="http://d.hatena.ne.jp/coro_1729/searchdiary?word=*[Tumblr]" class="broken_link">和訳</a><br />
http://(you).tumblr.com/api/read｜<a href="http://dobinn69.tumblr.com/api/read">うちのtumblrのxml</a></p>
<h3>xml抜粋</h3>
<pre class="brush: xml; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;tumblr version=&quot;1.0&quot;&gt;
 &lt;tumblelog name=&quot;dobinn69&quot; timezone=&quot;US/Eastern&quot; title=&quot;新規ドキュメント&quot;&gt;やっとタイトルを変えて写真変更の仕方が分かったレベル&lt;/tumblelog&gt;
 &lt;posts start=&quot;0&quot; total=&quot;5178&quot;&gt;
  &lt;post id=&quot;423624165&quot; url=&quot;http://dobinn69.tumblr.com/post/423624165&quot; url-with-slug=&quot;http://dobinn69.tumblr.com/post/423624165/x-117-suzukichiyo-ak47-naha&quot; type=&quot;photo&quot; date-gmt=&quot;2010-03-03 05:44:38 GMT&quot; date=&quot;Wed, 03 Mar 2010 00:44:38&quot; unix-timestamp=&quot;1267595078&quot; format=&quot;html&quot; reblog-key=&quot;bcque5Cz&quot; slug=&quot;x-117-suzukichiyo-ak47-naha&quot;&gt;
   &lt;photo-caption&gt;&amp;lt;/blockquote&amp;gt;&lt;/photo-caption&gt;
   &lt;photo-link-url&gt;http://ffffound.com/image/2c4ba8b6bcb787992657ac8266ce5ddbc20588bd&lt;/photo-link-url&gt;
   &lt;photo-url max-width=&quot;1280&quot;&gt;http://dobinn69.tumblr.com/photo/1280/423624165/1/tumblr_kyfivkpZ7u1qzlhmu&lt;/photo-url&gt;
   &lt;photo-url max-width=&quot;500&quot;&gt;http://29.media.tumblr.com/tumblr_kyfivkpZ7u1qzlhmuo1_500.jpg&lt;/photo-url&gt;
   &lt;photo-url max-width=&quot;400&quot;&gt;http://27.media.tumblr.com/tumblr_kyfivkpZ7u1qzlhmuo1_400.jpg&lt;/photo-url&gt;
   &lt;photo-url max-width=&quot;250&quot;&gt;http://26.media.tumblr.com/tumblr_kyfivkpZ7u1qzlhmuo1_250.jpg&lt;/photo-url&gt;
   &lt;photo-url max-width=&quot;100&quot;&gt;http://28.media.tumblr.com/tumblr_kyfivkpZ7u1qzlhmuo1_100.jpg&lt;/photo-url&gt;
   &lt;photo-url max-width=&quot;75&quot;&gt;http://25.media.tumblr.com/tumblr_kyfivkpZ7u1qzlhmuo1_75sq.jpg&lt;/photo-url&gt;
  &lt;/post&gt;
</pre>
<p>この中の<span class="note2">photo-url</span>のどれかが欲しいので最初にこう書いた。<br />
<span class="note3">tumblr.php</span></p>
<pre class="brush: php; title: ; notranslate">
$xml=simplexml_load_file(&quot;http://dobinn69.tumblr.com/api/read&quot;);
$pu=$xml-&gt;posts-&gt;post-&gt;photo-url[0];
</pre>
<p>するとこんなエラーが。<br />
<span class="note4">表示結果</span></p>
<pre class="brush: plain; title: ; notranslate">Parse error: syntax error, unexpected '[' in ファイル名 on line 2</pre>
<p>あるぇ？</p>
<p>なんでかなぁなんでかなぁと検索してみるけど配列へのアクセスは別に間違ってないようだ。</p>
<h3>試しに適当なxmlを作って上記方法でアクセスすると取得出来た。</h3>
<p><span class="note2">test.xml</span></p>
<pre class="brush: xml; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;aaa&gt;
 &lt;posts&gt;
  &lt;post&gt;
   &lt;testTitle&gt;test-title&lt;/testTitle&gt;
   &lt;testText&gt;test00&lt;/testText&gt;
   &lt;testText&gt;test10&lt;/testText&gt;
   &lt;testText&gt;test20&lt;/testText&gt;
   &lt;testText&gt;test30&lt;/testText&gt;
   &lt;testText&gt;test40&lt;/testText&gt;
  &lt;/post&gt;
 &lt;/posts&gt;
&lt;/aaa&gt;
</pre>
<p><span class="note3">test.php</span></p>
<pre class="brush: php; title: ; notranslate">
&lt;?php

$xml=simplexml_load_file(&quot;test.xml&quot;);
//print_r($xml);
$test=$xml-&gt;posts-&gt;post-&gt;testText[0];
print($test);
?&gt;
</pre>
<p><span class="note4">表示結果</span></p>
<pre class="brush: plain; title: ; notranslate">test00</pre>
<h3 id="simplexml_conclusion">そして結論</h3>
<p>二つを見比べてみる、どうも<span class="note2">要素名にハイフンが入っているのが問題</span>らしい気がする。</p>
<p>さっそくgoogleで<a href="http://www.google.co.jp/search?q=xml%E3%80%80%E3%83%8F%E3%82%A4%E3%83%95%E3%83%B3&#038;ie=utf-8&#038;oe=utf-8&#038;aq=t&#038;rls=org.mozilla:ja:official&#038;hl=ja&#038;client=firefox-a">「xml ハイフン」</a>と検索してみると結構でてきた！<br />
<span class="note2">simplexml_load_fileの問題じゃなかった</span>わけだ。</p>
<p>よってこんな風に変更</p>
<pre class="brush: php; title: ; notranslate">$pu=$xml-&gt;posts-&gt;post-&gt;{&quot;photo-url&quot;}[0];
</pre>
<p><a href="http://itpro.nikkeibp.co.jp/article/COLUMN/20080619/308711/">参考：92. ハイフン付きのメンバ変数名を参照する方法 </a></p>
<blockquote cite="http://itpro.nikkeibp.co.jp/article/COLUMN/20080619/308711/"><p>中括弧とクォーテーションで囲います。こうすることでハイフンが使われている要素名も参照できるようになります。</p></blockquote>
<p>なるほどー。</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.sakurachiro.com/2010/03/simplexml_load_file/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://blog.sakurachiro.com/2010/03/simplexml_load_file/" />
	</item>
		<item>
		<title>暫定版 photoshopのスウォッチ(.aco)を色相で並び替えるようにした</title>
		<link>http://blog.sakurachiro.com/2009/12/photoshop-aco-sort/</link>
		<comments>http://blog.sakurachiro.com/2009/12/photoshop-aco-sort/#comments</comments>
		<pubDate>Sat, 26 Dec 2009 18:11:58 +0000</pubDate>
		<dc:creator>まこと</dc:creator>
				<category><![CDATA[photoshop]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://blog.sakurachiro.com/2009/12/%e6%9a%ab%e5%ae%9a-photoshop%e3%81%ae%e3%82%b9%e3%82%a6%e3%82%a9%e3%83%83%e3%83%81-aco%e3%82%92%e8%89%b2%e7%9b%b8%e3%81%a7%e4%b8%a6%e3%81%b3%e6%9b%bf%e3%81%88%e3%82%8b%e3%82%88%e3%81%86%e3%81%ab/</guid>
		<description><![CDATA[とりあえずだけどやっと出来た、やっとだ。 スウォッチ(.aco)を色相か彩度か明度で並び替えるテスト 当初、色相の昇順だけを考えていたけど、どうせなのでHSBの昇順/降順6種類から選べるようにしてみた。 1．スウォッチを [...]]]></description>
			<content:encoded><![CDATA[<p>とりあえずだけどやっと出来た、やっとだ。<br />
<a href="http://sakurachiro.com/data/aco-sort/">スウォッチ(.aco)を色相か彩度か明度で並び替えるテスト</a></p>
<p>当初、色相の昇順だけを考えていたけど、どうせなのでHSBの昇順/降順6種類から選べるようにしてみた。</p>
<h3>1．スウォッチを書き出す</h3>
<p><a href="http://blog.sakurachiro.com/wp-content/uploads/2009/12/20091228-4.png" rel="shadowbox[sbpost-1542];player=img;" title="こんな感じ"><img src="http://blog.sakurachiro.com/wp-content/uploads/2009/12/20091228-4.png" alt="" title="こんな感じ" width="380" height="405" class="alignnone size-full wp-image-1547" /></a><br />
プリセットマネージャーからも書き出せるかもしれないけどやったことない。</p>
<h3>2．ソートの方法を選んで変換する</h3>
<p><a href="http://blog.sakurachiro.com/wp-content/uploads/2009/12/20091228-2.png" rel="shadowbox[sbpost-1542];player=img;" title="書き出しておいたスウォッチを選ぶ"><img src="http://blog.sakurachiro.com/wp-content/uploads/2009/12/20091228-2-480x355.png" alt="" title="書き出しておいたスウォッチを選ぶ" width="480" height="355" class="alignnone size-large wp-image-1546" /></a><br />
1．で保存したスウォッチを選択して<br />
ソートの基準を色相、彩度、明度から選んで「変換」</p>
<h3>3．ダウンロード</h3>
<p><a href="http://blog.sakurachiro.com/wp-content/uploads/2009/12/20091228-3.png" rel="shadowbox[sbpost-1542];player=img;" title="解析後"><img src="http://blog.sakurachiro.com/wp-content/uploads/2009/12/20091228-3-480x338.png" alt="" title="解析後" width="480" height="338" class="alignnone size-large wp-image-1545" /></a><br />
登録されている色数とRGBなんかと、ソート前の並び順とソート後の並び順を表示。</p>
<p>ソート済みファイルのダウンロード / 色数colors-西暦月日_時分秒.acoから保存先を選んでダウンロード、名前は変更しても問題なし。</p>
<p>こんな感じで使います。</p>
<p><span class="note2">追記｜2010-01-12</span><br />
不具合修正、<del datetime="2010-01-12T09:39:41+00:00">ついでに重複した色を削除するようにしてみた</del>。<br />
array_uniqueがローカルだと正常動作してるっぽいのに、サーバーにアップすると配列の先頭1つを残して全て削除してしまう、なにゆえ！？</p>
<p><span class="note2">追記2｜2010-01-12</span><br />
array_uniqueの第2引数にSORT_REGULARを設定したところローカルでもサーバー上でも同じ動作になった。<br />
さくらインターネットのarray_uniqueの設定はSORT_STRINGがデフォルトにでもなっているのでしょうか？<br />
ようわからん。</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.sakurachiro.com/2009/12/photoshop-aco-sort/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://blog.sakurachiro.com/2009/12/photoshop-aco-sort/" />
	</item>
		<item>
		<title>帰ってきた photoshopのスウォッチ(.aco)を色相で並び替えるようにしたい</title>
		<link>http://blog.sakurachiro.com/2009/12/aco3/</link>
		<comments>http://blog.sakurachiro.com/2009/12/aco3/#comments</comments>
		<pubDate>Sat, 26 Dec 2009 05:02:38 +0000</pubDate>
		<dc:creator>まこと</dc:creator>
				<category><![CDATA[photoshop]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://blog.sakurachiro.com/?p=1540</guid>
		<description><![CDATA[この記事は最新版があります。 ローカルではacoをソート出来るようになったんですが、アップロードすると動かない。 どうも.acoファイルの読み込みが失敗してるみたい。 色相で並び替えたらこんな感じ。 色相でソートしても明 [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.sakurachiro.com/2009/12/photoshop-aco-sort/">この記事は最新版があります。</a></p>
<p>ローカルではacoをソート出来るようになったんですが、アップロードすると動かない。<br />
どうも.acoファイルの読み込みが失敗してるみたい。</p>
<p>色相で並び替えたらこんな感じ。<br />
<a href="http://blog.sakurachiro.com/wp-content/uploads/2009/12/20091226-3.png" rel="shadowbox[sbpost-1540];player=img;" title="色相で並び替え"><img src="http://blog.sakurachiro.com/wp-content/uploads/2009/12/20091226-3.png" alt="" title="色相で並び替え" width="306" height="335" class="alignnone size-full wp-image-1541" /></a></p>
<p>色相でソートしても明度がめだつなぁ<br />
綺麗なグラデーションになるかと思ってたけど、HSBをうまいこと混ぜてソートしないとダメみたいだがようわからん。</p>
<p>とりあえず、次はファイルのアップロードと変換後のダウンロード出来るようにしなきゃ。</p>
<p>headerつけて、<a href="http://www.php.net/manual/ja/function.readfile.php">readfile</a>を使うのか？</p>
<p><span id="more-1540"></span></p>
<h3>前回からここまでにつまづいた部分と大体の流れ</h3>
<p>バイナリデータ(.aco)を16進数で開いて(<a href="http://jp2.php.net/manual/ja/function.bin2hex.php">bin2hex</a>)<br />
先頭から2番目のブロックの色数を<a href="http://jp2.php.net/manual/ja/function.hexdec.php">hexdec</a>で16進数から10進数に変換してループを回してRRRR GGGG BBBBを抽出。</p>
<h4>色相で並び替えたいのでRGBからHSBに変換する準備。</h4>
<p>RRRR GGGG BBBBからRR GG BBの配列を作成して<a href="http://jp2.php.net/manual/ja/function.max.php">max</a>と<a href="http://jp2.php.net/manual/ja/function.min.php">min</a>を使ってmaxとminを抽出、RGBと絡めてH(色相)を抽出。<br />
ついでにS(彩度)とB(明度)も調べ配列に入れとく。</p>
<h4>ソート</h4>
<p><a href="http://jp2.php.net/manual/ja/function.array-multisort.php">array_multisort</a>を使って[例3 データベースの結果をソートする]を参考にソート。</p>
<p><a href="http://jp2.php.net/manual/ja/function.str-pad.php">str_pad</a>などで隙間を埋めた。</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.sakurachiro.com/2009/12/aco3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://blog.sakurachiro.com/2009/12/aco3/" />
	</item>
		<item>
		<title>bin2hexと書こうとするとbin22hexに変換される。</title>
		<link>http://blog.sakurachiro.com/2009/12/bin2hex-bin22hex/</link>
		<comments>http://blog.sakurachiro.com/2009/12/bin2hex-bin22hex/#comments</comments>
		<pubDate>Fri, 25 Dec 2009 18:21:25 +0000</pubDate>
		<dc:creator>まこと</dc:creator>
				<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://blog.sakurachiro.com/2009/12/bin2hex%e3%81%a8%e6%9b%b8%e3%81%93%e3%81%86%e3%81%a8%e3%81%99%e3%82%8b%e3%81%a8bin22hex%e3%81%ab%e5%a4%89%e6%8f%9b%e3%81%95%e3%82%8c%e3%82%8b%e3%80%82/</guid>
		<description><![CDATA[google日本語入力のせいだ。 と、思う。 phpメモ bin2hex：バイナリを16進数で表示 hexdec：16進数を10進数に変換 dechex：10進数を16進数に変換 pack(&#8220;H*&#8221 [...]]]></description>
			<content:encoded><![CDATA[<p>google日本語入力のせいだ。<br />
と、思う。</p>
<h3>phpメモ</h3>
<p>bin2hex：バイナリを16進数で表示<br />
hexdec：16進数を10進数に変換</p>
<p>dechex：10進数を16進数に変換</p>
<p>pack(&#8220;H*&#8221;,文字列);：16進数をバイナリに変換？</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.sakurachiro.com/2009/12/bin2hex-bin22hex/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://blog.sakurachiro.com/2009/12/bin2hex-bin22hex/" />
	</item>
		<item>
		<title>array_multisort — 複数の多次元の配列をソートする</title>
		<link>http://blog.sakurachiro.com/2009/12/array_multisort/</link>
		<comments>http://blog.sakurachiro.com/2009/12/array_multisort/#comments</comments>
		<pubDate>Fri, 25 Dec 2009 11:47:08 +0000</pubDate>
		<dc:creator>まこと</dc:creator>
				<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://blog.sakurachiro.com/2009/12/array_multisort-%e2%80%94-%e8%a4%87%e6%95%b0%e3%81%ae%e5%a4%9a%e6%ac%a1%e5%85%83%e3%81%ae%e9%85%8d%e5%88%97%e3%82%92%e3%82%bd%e3%83%bc%e3%83%88%e3%81%99%e3%82%8b/</guid>
		<description><![CDATA[array_multisort — 複数の多次元の配列をソートするの 「例3 データベースの結果をソートする」が理解できない。悔しいやら情けないやら。 「こうゆうものだ」って覚えるようなものじゃない気がするんだよなぁ。  [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.php.net/manual/ja/function.array-multisort.php">array_multisort — 複数の多次元の配列をソートする</a>の<br />
「例3 データベースの結果をソートする」が理解できない。悔しいやら情けないやら。</p>
<pre class="brush: php; title: ; notranslate">
$ar1=array(&quot;name&quot;=&gt;&quot;サヨナラダンス&quot;,&quot;bpm&quot;=&gt;127);
$ar2=array(&quot;name&quot;=&gt;&quot;ハローグッバイ&quot;,&quot;bpm&quot;=&gt;88);
$ar3=array(&quot;name&quot;=&gt;&quot;WAGON&quot;,&quot;bpm&quot;=&gt;131);
$data=array($ar1,$ar2,$ar3);
print_r($data);

foreach ($data as $key =&gt; $row) {
    $name[$key]  = $row['name'];
    $bpm[$key] = $row['bpm'];
}

array_multisort($bpm,SORT_DESC,$data);
print_r($data);
</pre>
<pre class="brush: plain; title: ; notranslate">
//ソート前
Array (
　[0] =&gt; Array ( [name] =&gt; サヨナラダンス [bpm] =&gt; 127 )
　[1] =&gt; Array ( [name] =&gt; ハローグッバイ [bpm] =&gt; 88 )
　[2] =&gt; Array ( [name] =&gt; WAGON [bpm] =&gt; 131 )
)

//ソート後
Array (
　[0] =&gt; Array ( [name] =&gt; WAGON [bpm] =&gt; 131 )
　[1] =&gt; Array ( [name] =&gt; サヨナラダンス [bpm] =&gt; 127 )
　[2] =&gt; Array ( [name] =&gt; ハローグッバイ [bpm] =&gt; 88 )
)
</pre>
<p>「こうゆうものだ」って覚えるようなものじゃない気がするんだよなぁ。<br />
<a href="http://jp.php.net/manual/ja/control-structures.foreach.php">foreach</a>とセットでしか多次元の連想配列はソート出来ないのかな。</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.sakurachiro.com/2009/12/array_multisort/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://blog.sakurachiro.com/2009/12/array_multisort/" />
	</item>
		<item>
		<title>続 photoshopのスウォッチ(.aco)を色相で並び替えるようにしたい</title>
		<link>http://blog.sakurachiro.com/2009/12/aco2/</link>
		<comments>http://blog.sakurachiro.com/2009/12/aco2/#comments</comments>
		<pubDate>Tue, 22 Dec 2009 07:49:46 +0000</pubDate>
		<dc:creator>まこと</dc:creator>
				<category><![CDATA[photoshop]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://blog.sakurachiro.com/2009/12/%e7%b6%9a-photoshop%e3%81%ae%e3%82%b9%e3%82%a6%e3%82%a9%e3%83%83%e3%83%81-aco%e3%82%92%e8%89%b2%e7%9b%b8%e3%81%a7%e4%b8%a6%e3%81%b3%e6%9b%bf%e3%81%88%e3%82%8b%e3%82%88%e3%81%86%e3%81%ab%e3%81%97/</guid>
		<description><![CDATA[20091227｜とりあえずのが出来たのでアップしまんた。 暫定版 photoshopのスウォッチ(.aco)を色相で並び替えるようにした &#8212;&#8212;&#8212;&#8212;&#8212;&#821 [...]]]></description>
			<content:encoded><![CDATA[<p>20091227｜とりあえずのが出来たのでアップしまんた。<br />
<a href="http://blog.sakurachiro.com/2009/12/photoshop-aco-sort/">暫定版 photoshopのスウォッチ(.aco)を色相で並び替えるようにした</a><br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p><a href="http://blog.sakurachiro.com/2009/12/aco/">photoshopのスウォッチ(.aco)を色相で並び替えるようにしたい</a>の続き。</p>
<h3>まだまだ完成しないけど現状のメモ</h3>
<pre class="brush: php; title: ; notranslate">
$fileName=&quot;945066.aco&quot;;
$aco=fopen($fileName,&quot;rb&quot;);
$acoStr=fread($aco,filesize($fileName));
$acoStr=bin2hex($acoStr);

//基本
$setBlock=20;//色一区切り
$setHead=12;//頭出し分
$cutNum=12;//切り取る分
//色数
$colorMax=substr($acoStr,4,4);
echo hexdec($colorMax).&quot;&lt;br&gt;&quot;;

//
for($ii=0;$ii&lt;hexdec($colorMax);$ii++){
$nowBlock=($setBlock*$ii)+$setHead;
//
$colorName4[$ii]=substr($acoStr,$nowBlock,$cutNum);
$colorName4[$ii]=str_split($colorName4[$ii],4);
for($i=0;$i&lt;3;$i++){
$colorName2[$ii][$i]=substr($colorName4[$ii][$i],0,2);
}
}

print_r($colorName2);
fclose($aco);
</pre>
<pre class="brush: plain; title: ; notranslate">出力結果：
2
Array ( [0] =&gt; Array ( [0] =&gt; 50 [1] =&gt; 8b [2] =&gt; 94 ) [1] =&gt; Array ( [0] =&gt; 94 [1] =&gt; 50 [2] =&gt; 66 ) )
</pre>
<p><span id="more-1533"></span></p>
<h3>まず.acoの開き方を調べた</h3>
<p>.acoはバイナリなのでfopenにbで開く<br />
そのままだと化けてたので<br />
$acoのバイナリデータをbin2hexで16進数に</p>
<pre class="brush: php; title: ; notranslate">
$fileName=&quot;945066.aco&quot;;
$aco=fopen($fileName,&quot;rb&quot;);
$acoStr=fread($aco,filesize($fileName));
$acoStr=bin2hex($acoStr);

echo wordwrap($acoStr,4,&quot; &quot;,true);//出力結果を見やすくする為に入れた

fclose($aco);
</pre>
<pre class="brush: plain; title: ; notranslate">
$acot出力結果：
0001 0002 0000 5050 8b8b 9493 0000 0000 9493 5050 6666 0000 0002 0002 0000 5050 8b8b 9493 0000 0000 0008 30b9 30a6 30a9 30c3 30c1 0020 0031 0000 0000 9493 5050 6666 0000 0000 0008 30b9 30a6 30a9 30c3 30c1 0020 0032 0000
</pre>
<p>色の開始位置が先頭から12<br />
1セット0000 RRRR GGGG BBBB 0000の20<br />
必要な分が12</p>
<pre class="brush: php; title: ; notranslate">
$setBlock=20;//色一区切り
$setHead=12;//頭出し分
$cutNum=12;//切り取る分
</pre>
<p>.acoに何色登録されてるか抜き出す</p>
<pre class="brush: php; title: ; notranslate">
//色数
$colorMax=substr($acot,4,4);
echo hexdec($colorMax).&quot;&lt;br&gt;&quot;;
</pre>
<p><span class="note2">hexdec</span>：16進数を10進数で返す</p>
<h3>色を抜き出す</h3>
<p>ここをどうしたらいいんだろうかわからん。<br />
0000～0000の中身だけを取得する方法はないもんかな。</p>
<p><span class="note3">1セット(20)×色数</span>分シフトさせてく。</p>
<pre class="brush: php; title: ; notranslate">
for($ii=0;$ii&lt;hexdec($colorMax);$ii++){
$nowBlock=($setBlock*$ii)+$setHead;
</pre>
<pre class="brush: php; title: ; notranslate">
$colorName4[$ii]=substr($acoStr,$nowBlock,$cutNum);
$colorName4[$ii]=str_split($colorName4[$ii],4);
for($i=0;$i&lt;3;$i++){
$colorName2[$ii][$i]=substr($colorName4[$ii][$i],0,2);
}
}
</pre>
<p>RRRRGGGGBBBBを抜き出して<br />
$array[0]=RRRR<br />
$array[1]=GGGG<br />
$array[2]=BBBB<br />
みたいになるよう配列に入れて<br />
さらにRR GG BBになるよう2次元配列にいれた。<br />
入れ方がこれで正しいのか…</p>
<p><span class="note2">substr</span>：文字列の一部分を範囲指定して返す<br />
<span class="note2">str_split</span>：文字列を配列に変換</p>
<pre class="brush: php; title: ; notranslate">print_r($colorName2);
fclose($aco);
</pre>
<p><span class="note2">print_r</span>：変数の情報を吐き出す<br />
<span class="note2">var_dump</span>：print_rより吐き出す情報が多い<br />
<span class="note2">fclose</span>：ファイル閉じる</p>
<p>さて、この後はどうしたらいいんでしょう。<br />
完成するといいな。</p>
<h3>追記</h3>
<p>色相で並び替えるから<br />
RGBをHSBに変換して、Hでソートすればいいんですよね？<br />
RGBからHSBのHと出すにはr,g,bを比較しなきゃダメで<br />
ソートした後に移動させたら0000で包み込んで書き出す？<br />
最初にbin2hexしたから逆のことしなきゃダメなんかな？</p>
<p>2箇所にあるRGBの表記はどうやってまとめたらいいのかな</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.sakurachiro.com/2009/12/aco2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://blog.sakurachiro.com/2009/12/aco2/" />
	</item>
		<item>
		<title>photoshopのスウォッチ(.aco)を色相で並び替えるようにしたい</title>
		<link>http://blog.sakurachiro.com/2009/12/aco/</link>
		<comments>http://blog.sakurachiro.com/2009/12/aco/#comments</comments>
		<pubDate>Sun, 20 Dec 2009 13:20:58 +0000</pubDate>
		<dc:creator>まこと</dc:creator>
				<category><![CDATA[photoshop]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://blog.sakurachiro.com/2009/12/photoshop%e3%81%ae%e3%82%b9%e3%82%a6%e3%82%a9%e3%83%83%e3%83%81-aco%e3%82%92%e8%89%b2%e7%9b%b8%e3%81%a7%e4%b8%a6%e3%81%b3%e6%9b%bf%e3%81%88%e3%82%8b%e3%82%88%e3%81%86%e3%81%ab%e3%81%97%e3%81%9f/</guid>
		<description><![CDATA[20091227｜とりあえずのが出来たのでアップしまんた。 暫定版 photoshopのスウォッチ(.aco)を色相で並び替えるようにした &#8212;&#8212;&#8212;&#8212;&#8212;&#821 [...]]]></description>
			<content:encoded><![CDATA[<p>20091227｜とりあえずのが出来たのでアップしまんた。<br />
<a href="http://blog.sakurachiro.com/2009/12/photoshop-aco-sort/">暫定版 photoshopのスウォッチ(.aco)を色相で並び替えるようにした</a><br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p>何をどうしたらそんな事が出来るようになるのかわからんので、やってる事がずれてるかもしれんけどもメモ。</p>
<p>.acoの中身を見たい、<br />
バイナリエディタで見るしかないようだ。<br />
<a href="http://www.vector.co.jp/soft/win95/util/se079072.html">Stirling</a>を使ってみる。</p>
<p>16進数？なにそれ、まいったな。</p>
<h3>適当なスウォッチを何個か作って.acoで書き出して、見比べてみて判ったこと</h3>
<p><span style="background:#508b94;color:#fff;">#508b94</span> を2個登録したスウォッチをバイナリエディタで開くと以下の通り</p>
<pre class="brush: plain; title: ; notranslate">
00 01 00 02 00 00 50 50 8B 8B 94 93 00 00 00 00
50 50 8B 8B 94 93 00 00 00 02 00 02 00 00 50 50
8B 8B 94 93 00 00 00 00 00 08 30 B9 30 A6 30 A9
30 C3 30 C1 00 20 00 31 00 00 00 00 50 50 8B 8B
94 93 00 00 00 00 00 08 30 B9 30 A6 30 A9 30 C3
30 C1 00 20 00 32 00 00
</pre>
<p>2色目を<span style="background:#945066;color:#fff;">#945066</span>に変更したスウォッチは以下</p>
<pre class="brush: plain; title: ; notranslate">
00 01 00 02 00 00 50 50 8B 8B 94 93 00 00 00 00
94 93 50 50 66 66 00 00 00 02 00 02 00 00 50 50
8B 8B 94 93 00 00 00 00 00 08 30 B9 30 A6 30 A9
30 C3 30 C1 00 20 00 31 00 00 00 00 94 93 50 50
66 66 00 00 00 00 00 08 30 B9 30 A6 30 A9 30 C3
30 C1 00 20 00 32 00 00
</pre>
<p>最初の00 01と最後の00 00は定型ぽい<br />
次の00 02が登録されてる色の数、<br />
3つ登録してあるスウォッチは00 03で、58個登録されてるスウォッチは00 3Aだった。<br />
(<a href="http://hogehoge.tk/tool/number.html">2進数、8進数、10進数、16進数相互変換</a>で変換させてもらってます。)</p>
<p>次の00 00がよく分からないけど区切り？<br />
その後の50 50 8B 8B 94 93がhex値、前半2桁だけが有効？で00 00で閉じる？</p>
<pre class="brush: plain; title: ; notranslate">00 08 30 B9 30 A6 30 A9 30 C3 30 C1 00 20 00</pre>
<p>も区切りかな</p>
<p>hex値ぽいところを以下のようにガーっと00にしてもちゃんと読み込む</p>
<pre class="brush: plain; title: ; notranslate">
00 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 02 00 02 00 00 50 50
8B 8B 94 93 00 00 00 00 00 08 30 B9 30 A6 30 A9
30 C3 30 C1 00 20 00 31 00 00 00 00 94 93 50 50
66 66 00 00 00 00 00 08 30 B9 30 A6 30 A9 30 C3
30 C1 00 20 00 32 00 00
</pre>
<p>02 00 02 00からが本当の色設定？</p>
<h3>phpのテスト</h3>
<pre class="brush: xml; title: ; notranslate">
&lt;!-- rgb.html --&gt;
&lt;form id=&quot;form1&quot; name=&quot;form1&quot; method=&quot;post&quot; action=&quot;rgb.php&quot;&gt;
&lt;ul&gt;&lt;li&gt;&lt;label for=&quot;rr&quot;&gt;r&lt;/label&gt;:&lt;input type=&quot;text&quot; name=&quot;rr&quot; id=&quot;rr&quot; max=&quot;3&quot; /&gt;&lt;/li&gt;
&lt;li&gt;&lt;label for=&quot;gg&quot;&gt;g&lt;/label&gt;:&lt;input type=&quot;text&quot; name=&quot;gg&quot; id=&quot;gg&quot; max=&quot;3&quot; /&gt;&lt;/li&gt;
&lt;li&gt;&lt;label for=&quot;bb&quot;&gt;b&lt;/label&gt;:&lt;input type=&quot;text&quot; name=&quot;bb&quot; id=&quot;bb&quot; max=&quot;3&quot; /&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;input type=&quot;submit&quot; /&gt;
&lt;/form&gt;
</pre>
<pre class="brush: php; title: ; notranslate">
// rgb.php
$r=hexdec($_POST[&quot;rr&quot;]);
$g=hexdec($_POST[&quot;gg&quot;]);
$b=hexdec($_POST[&quot;bb&quot;]);
//
$max=max($r,$g,$b);
$min=min($r,$g,$b);
print &quot;max:&quot;.$max.&quot;&lt;Br&gt;&quot;;
print &quot;min:&quot;.$min.&quot;&lt;Br&gt;&quot;;
print $_POST[&quot;rr&quot;].&quot;&lt;Br&gt;&quot;;
print $_POST[&quot;gg&quot;].&quot;&lt;Br&gt;&quot;;
print $_POST[&quot;bb&quot;].&quot;&lt;Br&gt;&quot;;

if($max==$min){
	$hue=0;
}
else if($g==$max) {
$hue=($b-$r)/($max-$min)*60+120;
}
else if($b==$max) {
$hue=($r-$g)/($max-$min)*60+240;
}
else if($g&lt;$b){
$hue=($g-$b)/($max-$min)*60+360;
}
else{
$hue=($g-$b)/($max-$min)*60;
}
print &quot;hue値&quot;.$hue;
</pre>
<p>でhexからhueを取り出せた。</p>
<h3>あと必要な事</h3>
<p>.acoの色の格納のされ方と範囲指定しての取り出し方<br />
phpでバイナリを読む方法<br />
とか？<br />
方向はあってるんのでしょうか…</p>
<h3>とりあえずphpで読み込んでみた</h3>
<p>辞書を引きながら、こんな感じに。</p>
<pre class="brush: php; title: ; notranslate">$fname=&quot;945066.aco&quot;;
$aco=fopen($fname,&quot;rb&quot;);
$str=fread($aco,filesize($fname));
$str=bin2hex($str);
echo $str;

$aco_ar=explode('0000',$str);
print_r($aco_ar);

fclose($aco);
</pre>
<p>出力結果</p>
<pre class="brush: plain; title: ; notranslate">
00010002000050508b8b949300000000949350506666000000020002000050508b8b949300000000000830b930a630a930c330c1002000310000000094935050666600000000000830b930a630a930c330c1002000320000Array
(
    [0] =&gt; 00010002
    [1] =&gt; 50508b8b9493
    [2] =&gt;
    [3] =&gt; 949350506666
    [4] =&gt; 00020002
    [5] =&gt; 50508b8b9493
    [6] =&gt;
    [7] =&gt; 000830b930a630a930c330c100200031
    [8] =&gt;
    [9] =&gt; 949350506666
    [10] =&gt;
    [11] =&gt; 000830b930a630a930c330c100200032
    [12] =&gt;
)
</pre>
<p><span class="note2">メモ</span><br />
explode(&#8216;区切り文字&#8217;,文字列);<br />
explode(&#8217;0000&#8242;,$str);</p>
<p>0000で区切ったけど、これだと#000が登場した時に区切り文字になってしまう。</p>
<p><span class="note2">メモ2</span><br />
どうゆう風にしてけばいいんだろ<br />
最初の2バイトを飛ばして、次の2バイトに格納されてる色の数を取得<br />
前半<em>00 00 RR RR GG GG BB BB 00 00</em>で1セット<br />
RR RRなどそれぞれの後半2文字を飛ばす<br />
000830b930a630a930c330c1002000の前に出てくるRRRR GGGG BBBBを書き換える</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.sakurachiro.com/2009/12/aco/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://blog.sakurachiro.com/2009/12/aco/" />
	</item>
		<item>
		<title>ヘッダーの背景画像をランダムに表示させたくなって知恵を絞る、の巻</title>
		<link>http://blog.sakurachiro.com/2009/10/header-bgimage-random/</link>
		<comments>http://blog.sakurachiro.com/2009/10/header-bgimage-random/#comments</comments>
		<pubDate>Mon, 05 Oct 2009 18:29:02 +0000</pubDate>
		<dc:creator>まこと</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[さくらちろ]]></category>
		<category><![CDATA[ランダム]]></category>
		<category><![CDATA[画像]]></category>

		<guid isPermaLink="false">http://blog.sakurachiro.com/?p=1214</guid>
		<description><![CDATA[先日追加したテンプレート（x-ran-zatsu）のヘッダー画像が何パターンかあるので せっかくだから全部使ってしまおうと ランダムで背景画像を表示するjavascriptを追加してみたら、これがうまくいかない。 うまく [...]]]></description>
			<content:encoded><![CDATA[<p>先日追加したテンプレート（x-ran-zatsu）のヘッダー画像が何パターンかあるので<br />
せっかくだから全部使ってしまおうと<br />
ランダムで背景画像を表示するjavascriptを追加してみたら、これがうまくいかない。</p>
<p>うまくいかないといっても、htmlに使えば動くんだけど、wordpress（php）で読み込むと画像が消えてしまう。</p>
<p>これがその時書いたjavascriptで<br />
読み込んだ時のミリ秒が奇数か偶数かで分岐させて、#headerの背景を差し替える。<br />
phpで使う場合jsの読み込ませる場所が違うのかな？</p>
<pre class="brush: jscript; title: ; notranslate">
window.onload=function(){
	headsw();
}

function headsw(){
var dt = new Date();
ms=dt.getMilliseconds();
//console.log(&quot;ms:&quot;+ms);
if(ms%2==0){
document.getElementById(&quot;header&quot;).style.backgroundImage=&quot;url(img/common/header.jpg)&quot;

}else{
document.getElementById('header').style.backgroundImage='url(img/common/header-2.jpg)'
}
}
</pre>
<p>関係ないけどキーボードの調子がすこぶる悪い。<br />
文字側のenter（テンキー側のは反応する）やc,v,F7あたりが反応したり、しなかったり、延々と一文字が入力され続けたり。</p>
<p>さて、粘ってみたけど、うまい解決法も閃かないので別の方法を考える事にした。<br />
せっかくwordpressでphpを使っているのだから、phpで出来ないかね？と辞書を片手にシコシコ書いてみたら、とりあえず動くだけというものだけど、出来たので手順を晒してみます。</p>
<p><span id="more-1214"></span></p>
<h3>まず画像を表示させてみる</h3>
<p>test-sw.phpという名前のファイルを作成して以下を記述</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
header('Content-Type: image/jpeg');
readfile(&quot;img/common/header-2.jpg&quot;);
?&gt;
</pre>
<p>やった、localhostから確認するとheader-2.jpgが表示された。</p>
<p>次にこのphpをcssに読み込ませてみる。<br />
<span class="note3">css/test-css.css</span></p>
<pre class="brush: css; title: ; notranslate">
#header{
	background:url(../test-sw.php) no-repeat;
	border:1px solid #f33;
	height:400px;
	width:400px;
}
</pre>
<p>test表示用のphpを作ってtest-css.cssを読み込ませる。<br />
<span class="note3">test-oya.php</span></p>
<pre class="brush: php; title: ; notranslate">
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
&lt;head&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;
&lt;title&gt;test&lt;/title&gt;

&lt;link href=&quot;css/test-css.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;div id=&quot;header&quot;&gt;head&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>やった、#headerの背景にheader-2.jpgが表示された。</p>
<p>背景画像を表示させる事は出来たので<br />
次は、画像の選び方を考える。</p>
<p>ランダムに切り替えたい背景画像だけを集めたフォルダを作って、そのフォルダ内にある画像を配列に入れられないか？<br />
これが出来れば、いちいちtest-sw.phpを変更する必要がなくて、背景画像を集めたフォルダに画像をぶっこめば済むようになる。</p>
<p>辞書を引くと、opendir()とreadfir()でディレクトリ操作ができるそうだ。<br />
<span class="note3">test-sw.phpに追加</span></p>
<pre class="brush: php; title: ; notranslate">
$dn=opendir(img/header);
while($file=readdir($dn)){
	echo &quot;ファイル名：$file&lt;br&gt;&quot;;
}
closedir($dn);
</pre>
<p><span class="note3">出力結果例</span></p>
<pre class="brush: plain; title: ; notranslate">
ファイル名：.
ファイル名：..
ファイル名：header-2.jpg
ファイル名：header-3.jpg
ファイル名：header-4.jpg
ファイル名：header-5.jpg
ファイル名：header-6.jpg
ファイル名：header.jpg
</pre>
<p>ん？<br />
ファイル名：.<br />
ファイル名：..<br />
？<br />
なんだこれ。</p>
<p>よくわからないのであとで調べるとして今はif文で弾いとく、<br />
ついでにマジックナンバー的なフォルダ階層を潰して、抜き出したファイル名を配列に入れる。</p>
<p><span class="note3">test-sw.phpを変更</span></p>
<pre class="brush: php; title: ; notranslate">
$headimgdir='img/header';

$dn=opendir($headimgdir);
while($file=readdir($dn)){
	if($file!='.' &amp;&amp; $file!='..'){
		$files[]=$file;
	}
}
closedir($dn);
</pre>
<p>これで画像が入った配列が完成。<br />
ここからランダムにピックアップさせる方法を調べる。</p>
<p>php4～で「array_rand(配列);」というものがあった、配列のインデックスをランダムに取得できるらしい。<br />
これを使ってみる。<br />
<span class="note3">test-sw.phpを変更</span></p>
<pre class="brush: php; title: ; notranslate">
$imgnum= array_rand($files);
$imgpath=$files[$imgnum];
header('Content-Type: image/jpeg');
readfile($headimgdir.'/'.$imgpath);
</pre>
<p>readfileはフォルダ階層と配列からの値に変更。</p>
<h3>最終的なtest-sw.php</h3>
<pre class="brush: php; title: ; notranslate">
&lt;?php
$headimgdir='img/header';

$dn=opendir($headimgdir);
while($file=readdir($dn)){
	if($file!='.' &amp;&amp; $file!='..'){
		$files[]=$file;
	}
}
closedir($dn);

$imgnum= array_rand($files);
$imgpath=$files[$imgnum];
header('Content-Type: image/jpeg');
readfile($headimgdir.'/'.$imgpath);

?&gt;
</pre>
<p>完成。</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.sakurachiro.com/2009/10/header-bgimage-random/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://blog.sakurachiro.com/2009/10/header-bgimage-random/" />
	</item>
		<item>
		<title>ついったなうぷらぎん</title>
		<link>http://blog.sakurachiro.com/2009/09/%e3%81%a4%e3%81%84%e3%81%a3%e3%81%9f%e3%81%aa%e3%81%86%e3%81%b7%e3%82%89%e3%81%8e%e3%82%93/</link>
		<comments>http://blog.sakurachiro.com/2009/09/%e3%81%a4%e3%81%84%e3%81%a3%e3%81%9f%e3%81%aa%e3%81%86%e3%81%b7%e3%82%89%e3%81%8e%e3%82%93/#comments</comments>
		<pubDate>Thu, 24 Sep 2009 07:49:42 +0000</pubDate>
		<dc:creator>まこと</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[Twitter]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://blog.sakurachiro.com/?p=1013</guid>
		<description><![CDATA[simpleだと右側にあってnormalだとフッターあたりにある、ついったーの投稿を表示するやつをアップしまんた 使いたい方は勝手に持っていってください。 コメントも連絡もいりません、改造もなにもかもお好きにどうぞ。 [ [...]]]></description>
			<content:encoded><![CDATA[<p>simpleだと右側にあってnormalだとフッターあたりにある、<a href="http://sakurachiro.com/data/wp-plugin/">ついったーの投稿を表示するやつ</a>をアップしまんた<br />
使いたい方は勝手に持っていってください。<br />
コメントも連絡もいりません、改造もなにもかもお好きにどうぞ。</p>
<p><em class="note2">[追記 / 20100621]</em><br />
ダウンロードしても、中身が真っ白になってました(報告ありがとうございました。そしてごめんなさい)。</p>
<p>zipに包んでアップしなおしたので今度は大丈夫だと思います。<br />
ついでにサンプルCSSと画像を梱包しました。</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.sakurachiro.com/2009/09/%e3%81%a4%e3%81%84%e3%81%a3%e3%81%9f%e3%81%aa%e3%81%86%e3%81%b7%e3%82%89%e3%81%8e%e3%82%93/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://blog.sakurachiro.com/2009/09/%e3%81%a4%e3%81%84%e3%81%a3%e3%81%9f%e3%81%aa%e3%81%86%e3%81%b7%e3%82%89%e3%81%8e%e3%82%93/" />
	</item>
	</channel>
</rss>

