<?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>.dotown lab</title>
	<link>http://dot-town-lab.com/laboratory/</link>
	<description>WEB製作に関連する事を書き留めて置く為のサイトになります。</description>
	<language>ja</language>
	<copyright>Copyright 2026 .dotown lab</copyright>
	<managingEditor>m.satoshi.1984@gmail.com (Satoshi Mori)</managingEditor>
	<webMaster>m.satoshi.1984@gmail.com (Satoshi Mori)</webMaster>
	<pubDate>Thu, 11 Jun 2015 13:14:32 +0900</pubDate>
	<lastBuildDate>Tue, 10 Mar 2026 12:56:06 +0900</lastBuildDate>
	<category>Weblog</category>
	<generator>PHP</generator>
	<docs>http://blogs.law.harvard.edu/tech/rss</docs>
<item>
	<title>テキストボックスをセレクトボックスのように使用するjQueryプラグイン</title>
	<link>http://dot-town-lab.com/laboratory/item/77</link>
	<description><![CDATA[Option要素が100個以上あるセレクトボックスを100個以上配置するという無謀なページを以前作成し、尋常じゃない表示遅延が発生したので、それを解消する為に作成したプラグインになります。テキストボックスを100...]]></description>
	<author>Satoshi Mori</author>
	<category>jQuery</category>
	<pubDate>Thu, 11 Jun 2015 13:14:32 +0900</pubDate>
	<content:encoded><![CDATA[<p>Option要素が100個以上あるセレクトボックスを100個以上配置するという無謀なページを以前作成し、尋常じゃない表示遅延が発生したので、それを解消する為に作成したプラグインになります。</p>
<p>テキストボックスを100個配置して、共通のOption要素を1つ用意するだけで良いので、表示速度が格段に速まります。また、絞り込み検索の機能も付けているので、Option要素が多くなっても問題無く利用できると思います。</p>
<br>
<h4>jquery.smSearchInputSelector.js</h4>
<p>Inputタグのテキストボックスをセレクトボックスのような選択式の要素に変換します。</p>
<p>予め用意しておいた、選択要素の中の値しか入力できません。</p>
<p>テキストボックスに文字列を入力すると、絞り込み検索を行います。</p>
<ul class="list_dot">
<li><a href="/laboratory/views/demos/js/jquery.smSearchInputSelector.js" target="_blank">jquery.smSearchInputSelector.js</a></li>
<li><a href="/laboratory/views/demos/js/jquery.smSearchInputSelector.min.js" target="_blank">jquery.smSearchInputSelector.min.js</a></li>
</ul>
<br>
<h4>Options</h4>
<p>追記：「selected」と「addfontsize」を追加しました。</p>
<table class="options">
<thead>
<tr><th>Name</th><th>Default</th><th>Description</th></tr>
</thead>
<tbody>
<tr><td><b>uniquename</b></td>
<td>jsSearchInputSelector <small>(string)</small></td>
<td>プラグインを適用する際に使用するの名称と同じ名称を指定する。<br><small>例：$('.hoge').smSearchInputSelector({uniquename:'hoge'});</small></td></tr>
<tr><td><b>classes</b></td>
<td>{<br>selector:'jsSearchInputSelector',<br>hidden:'hidden',<br>dropdown:'dropdown'<br>} <small>(object)</small></td>
<td>各要素のクラス名（変更する場合は全てを定義）</td></tr>
<tr><td><b>selector</b></td>
<td>[] <small>(object)</small></td>
<td>選択要素のオブジェクトを挿入<br><small>[{value:'',name:'',search:''},...]</small></td></tr>
<tr><td><b>selected</b></td>
<td>function</td>
<td>選択時のコールバック関数<br><small>例：function(val){}</small></td></tr>
<tr><td><b>max-height</b></td>
<td>250 <small>(int)</small></td>
<td>ドロップダウンの最大の高さ</td></tr>
<tr><td><b>addfontsize</b></td>
<td>0 <small>(int)</small></td>
<td>文字サイズの調整</td></tr>
</tbody>
</table>
<br>
<h4>data属性</h4>
<table class="options">
<thead>
<tr><th>Name</th><th>Description</th></tr>
</thead>
<tbody>
<tr><td><b>data-value=""</b></td>
<td>初期値を入力</td></tr>
</tbody>
</table>
<br>
<h4>CSS</h4>
<pre>/*
 * 選択リストのスタイルシート
 * .jsSearchInputSelectorは「classes.selector」と同じにする
 */
.jsSearchInputSelector{}
.jsSearchInputSelector.dropdown{ display:none; position:absolute; top:0; left:0; background-color:#fff; box-shadow:0 2px 3px rgba(0,0,0,0.2); }
.jsSearchInputSelector.dropdown div{ border:1px solid #7f9db9; }
.jsSearchInputSelector.dropdown dl dt{ padding:4px; }
.jsSearchInputSelector.dropdown dl dt p{ line-height:1; border:1px solid #c9c9c9; }
.jsSearchInputSelector.dropdown dl dt p input{ padding:4px 1%; width:98%; font-size:14px; border:none; }
.jsSearchInputSelector.dropdown dl dd{}
.jsSearchInputSelector.dropdown div ul{ margin:0; padding:0; list-style:none; overflow:auto; }
.jsSearchInputSelector.dropdown div ul li{ padding:1px 3px; color:#000; line-height:1; cursor:default; user-select:none; -webkit-user-select:none; -moz-user-select:none; -ms-user-select:none; }
.jsSearchInputSelector.dropdown div ul li.selected{ color:#fff; background-color:#aaa; }
.jsSearchInputSelector.dropdown div ul li:hover{ color:#fff; background-color:#1e90ff; }
</pre>
<br>
<h4>記述例（Javascript）</h4>
<pre>/*
 * value : 値
 * name : 選択リストに表示する名称
 * search : 検索に該当する文字列
 */
var obj = [
    {value:'', name:'', search:''},
    {value:1, name:'hoge1', search:'hoge1ほげ1ホゲ1'},
    {value:2, name:'hoge2', search:'hoge2ほげ2ホゲ2'},
    {value:3, name:'hoge3', search:'hoge3ほげ3ホゲ3'},
];

$(function(){
    $('.selector').smSearchInputSelector({
        uniquename : 'selector',
        selector : obj,
        selected : function (val) {
            console.log(val);
        }
    });
});</pre>
<br>
<h4>記述例（HTML）</h4>
<pre>&lt;!-- value属性に初期値を入れる場合は「obj」の「name値」を入れる。 --&gt;
&lt;div&gt;&lt;input class=&quot;selector&quot; type=&quot;text&quot; name=&quot;hogehoge[]&quot; data-value=&quot;&quot; value=&quot;&quot; /&gt;&lt;/div&gt;
&lt;div&gt;&lt;input class=&quot;selector&quot; type=&quot;text&quot; name=&quot;hogehoge[]&quot; data-value=&quot;2&quot; value=&quot;hoge2&quot; /&gt;&lt;/div&gt;
&lt;div&gt;&lt;input class=&quot;selector&quot; type=&quot;text&quot; name=&quot;hogehoge[]&quot; data-value=&quot;&quot; value=&quot;&quot; /&gt;&lt;/div&gt;</pre>]]></content:encoded>
</item>
<item>
	<title>PHPを使ってテキストファイルへの書き出しと読み込み</title>
	<link>http://dot-town-lab.com/laboratory/item/76</link>
	<description><![CDATA[たまに使う事があるのでメモ。PHP: fopen - Manualファイルに書き出し$path = $_SERVER['DOCUMENT_ROOT'].'/hoge/file.txt';$handle = fopen($path, 'a+');$str = &quot;文字列1,文字列2\n&quot;;fwrite($handle,...]]></description>
	<author>Satoshi Mori</author>
	<category>PHP</category>
	<pubDate>Sat, 30 May 2015 11:11:01 +0900</pubDate>
	<content:encoded><![CDATA[<p>たまに使う事があるのでメモ。</p>
<br>
<ul class="list_dot">
<li><a href="http://php.net/manual/ja/function.fopen.php" target="_blnk">PHP: fopen - Manual</a></li>
</ul>
<br>
<h4>ファイルに書き出し</h4>
<pre>$path = $_SERVER['DOCUMENT_ROOT'].'/hoge/file.txt';
$handle = fopen($path, 'a+');

$str = &quot;文字列1,文字列2\n&quot;;
fwrite($handle, $str);

fclose($handle);</pre>
<br>
<h4>ファイルを読み込み</h4>
<pre>$path = $_SERVER['DOCUMENT_ROOT'].'/hoge/file.txt';
$handle = fopen($path, 'r');

$file = fread($handle, filesize($path));

fclose($handle);

$file = explode(&quot;\n&quot;, $file);
foreach ($file as $row) {
    $cols = explode(',', $row);
    echo trim($cols[0]).' : '.trim($cols[1]).'&lt;br&gt;';
}

/*
 * 出力結果
 * 文字列1 : 文字列2
*/</pre>]]></content:encoded>
</item>
<item>
	<title>テーブルのヘッダを常に表示させるjQueryプラグインを作ってみた</title>
	<link>http://dot-town-lab.com/laboratory/item/75</link>
	<description><![CDATA[テーブルのヘッダを固定させる方法を探していたのですが、「thead」と「tbody」を分けた方法や、テーブルの幅が固定された方法しか見つけられなかったので、jQueryプラグインを試しに作ってみました。jquery.smTh...]]></description>
	<author>Satoshi Mori</author>
	<category>jQuery</category>
	<pubDate>Wed, 17 Sep 2014 19:41:06 +0900</pubDate>
	<content:encoded><![CDATA[<p>テーブルのヘッダを固定させる方法を探していたのですが、「thead」と「tbody」を分けた方法や、テーブルの幅が固定された方法しか見つけられなかったので、jQueryプラグインを試しに作ってみました。</p>
<br>
<h4>jquery.smTheadfixed.js</h4>
<p>対応するテーブルは、theadタグとtbodyタグを使った単純なテーブルで、rowspanやcolspanを使わないテーブルを想定しています。</p>
<p>テーブルの横幅は、固定と可変どちらでも対応するようにしています。</p>
<ul class="list_dot">
<li><a href="/laboratory/views/demos/js/jquery.smTheadfixed.js" target="_blank">jquery.smTheadfixed.js</a></li>
<li><a href="/laboratory/views/demos/js/jquery.smTheadfixed.min.js" target="_blank">jquery.smTheadfixed.min.js</a></li>
</ul>
<br>
<h4>Options</h4>
<table class="options">
<thead>
<tr><th>Name</th><th>Default</th><th>Description</th></tr>
</thead>
<tbody>
<tr>
<td><b>border_top</b></td>
<td>0 <small>(number)</small></td>
<td>上辺ボーダーの幅を指定</td>
</tr>
<tr>
<td><b>border_left</b></td>
<td>0 <small>(number)</small></td>
<td>左辺ボーダーの幅を指定</td>
</tr>
<tr>
<td><b>thead_row</b></td>
<td>0 <small>(number)</small></td>
<td>theadの基準行番号</td>
</tr>
<tr>
<td><b>tbody_row</b></td>
<td>0 <small>(number)</small></td>
<td>tbodyの基準行番号</td>
</tr>
</tbody>
</table>
<br>
<h4>記述例</h4>
<p>tableタグにクラス名を指定、theadタグとtbodyタグを使用する。</p>
<pre>&lt;script type=&quot;text/javascript&quot;&gt;
//&lt;![CDATA[
    $(function(){
        $('.jsTheadfixed').smTheadfixed();
    });
//]]&gt;
&lt;/script&gt;

&lt;table class=&quot;jsTheadfixed&quot;&gt;
    &lt;thead&gt;
        &lt;tr&gt;
            &lt;th&gt;ID&lt;/th&gt;
            &lt;th&gt;Name&lt;/th&gt;
            &lt;th&gt;Date&lt;/th&gt;
        &lt;/tr&gt;
    &lt;/thead&gt;
    &lt;tbody&gt;
        &lt;tr&gt;
            &lt;td&gt;1&lt;/td&gt;
            &lt;td&gt;AAA&lt;/td&gt;
            &lt;td&gt;2014-01-01&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;2&lt;/td&gt;
            &lt;td&gt;BBB&lt;/td&gt;
            &lt;td&gt;2014-02-01&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;3&lt;/td&gt;
            &lt;td&gt;CCC&lt;/td&gt;
            &lt;td&gt;2014-03-01&lt;/td&gt;
        &lt;/tr&gt;
    &lt;/tbody&gt;
&lt;/table&gt;</pre>]]></content:encoded>
</item>
<item>
	<title>jQueryでのイベントハンドラの設定と削除</title>
	<link>http://dot-town-lab.com/laboratory/item/73</link>
	<description><![CDATA[イベントを設定する// クリックイベントを設定する$('p').on('click', function(e){    console.log(e.type);});// 複数のイベントを同時に設定する$('p').on('mouseover mouseout', function(e){    console.log...]]></description>
	<author>Satoshi Mori</author>
	<category>jQuery</category>
	<pubDate>Tue, 10 Jun 2014 12:27:28 +0900</pubDate>
	<content:encoded><![CDATA[<h4>イベントを設定する</h4>
<pre>// クリックイベントを設定する
$('p').on('click', function(e){
    console.log(e.type);
});

// 複数のイベントを同時に設定する
$('p').on('mouseover mouseout', function(e){
    console.log(e.type);
});

// 関数を使用してイベントを設定する
$('p').on('click', eventhandler(1));
function eventhandler(n) {
    console.log(n);
    return function (e) {
        console.log(e.type);
    };
}</pre>
<br>
<h4>イベントを削除する</h4>
<pre>// クリックイベントを削除する
$('p').off('click');

// 全てのイベントを削除する
$('p').off();</pre>]]></content:encoded>
</item>
<item>
	<title>使えそうなPHPのユーザー定義関数いろいろ（2）</title>
	<link>http://dot-town-lab.com/laboratory/item/72</link>
	<description><![CDATA[今後使いそうな、PHPのユーザー定義関数をメモ。第二弾。前回の記事はこちら→使えそうなPHPのユーザー定義関数いろいろ文字列を検索ワード用に変換指定の文字列をSQLの検索文字用に変換する関数。// 1:文字列func...]]></description>
	<author>Satoshi Mori</author>
	<category>PHP</category>
	<pubDate>Fri, 02 May 2014 12:00:14 +0900</pubDate>
	<content:encoded><![CDATA[<p>今後使いそうな、PHPのユーザー定義関数をメモ。第二弾。</p>
<p>前回の記事はこちら→<a href="/laboratory/item/71">使えそうなPHPのユーザー定義関数いろいろ</a></p>
<br>
<h4>文字列を検索ワード用に変換</h4>
<p>指定の文字列をSQLの検索文字用に変換する関数。</p>
<pre>// 1:文字列
function strConvertSearch($str) {
    if (!$str) return $str;
    $str = urldecode($str);
    $str = trim($str);
    $str = stripslashes($str);
    $str = mb_convert_kana($str, &quot;aKs&quot;);
    $str = preg_replace('/\s+/', ' ', $str);
    return $str;
}</pre>
<br>
<h4>文字列を指定数ごとに折り返す</h4>
<p>指定の文字列をn文字数間隔で折り返す、または文字列を挿入する関数。</p>
<pre>// 1:文字列, 2:間隔数, 3:挿入文字（配列指定）
function strSplitByWidth($str = '', $width = 30, $deco = array()) {
    if (!$str) return '';
    $strs = explode(&quot;\n&quot;, $str);
    $deco[0] = !empty($deco[0]) ? (!$this-&gt;isNullEmpty($deco[0]) ? $deco[0] : '') : '';
    $deco[1] = !empty($deco[1]) ? (!$this-&gt;isNullEmpty($deco[1]) ? $deco[1] : &quot;\n&quot;) : &quot;\n&quot;;
    $result   = '';
    $i = 0;
    foreach ($strs as $str) {
        $str = trim($str);
        if ($str) {
            $position = 0;
            while ($part = mb_strimwidth($str, $position, $width)) {
                $position += mb_strlen($part);
                $result .= ($i ? $deco[0] : ''). $part. $deco[1];
                $i ++;
            }
        } else {
            $result .= $deco[1];
        }
    }
    return $result;
}</pre>
<br>
<h4>配列を指定文字区切りの文字列にして空の場合はNULLを返す</h4>
<p>implode関数と同じ処理。配列の中身が空の場合はnullを返す。</p>
<p>※isNullEmpty関数は「<a href="/laboratory/item/71">使えそうなPHPのユーザー定義関数いろいろ</a>」に記載しています。</p>
<pre>// 1:文字列, 2:配列
function implode_null($str = '', $arr = array()) {
    if (!$arr) return null;
    $arr = is_array($arr) ? $arr : array($arr);
    $result = '';
    foreach ($arr as $value) {
        if (isNullEmpty($value)) continue;
        $result .= ($result ? $str : ''). $value;
    }
    return $result ? $result : null;
}</pre>
<br>
<h4>共通の値を配列から除外する</h4>
<p>配列の値を比較して、同じ値があれば削除する関数。</p>
<pre>// 1:基準配列, 2:削除配列
function array_exclusion($arr = array(), $ex_arr = array()) {
    if (!$arr || !$ex_arr) return $arr;
    $result = array();
    foreach ($arr as $key =&gt; $name) {
        if (!in_array($name, $ex_arr)) $result[$key] = $name;
    }
    return $result;
}</pre>
<br>
<h4>Google Calendar API v3の日付を取得</h4>
<p>Google Calendar API v3を利用する時に使用する日付を取得する。</p>
<p>Google Calendar API v3に関しては「<a href="/laboratory/item/62">Google Calendar API v3を利用して祝日を取得してみた</a>」を参照してください。</p>
<pre>// 1:日付（配列での複数指定可）
function getGoogleHolidayDate($date = null) {
    $date = $date ? $date : date('Y-m-01');
    $dates = is_array($date) ? $date : array($date);
    asort($dates);
    $i = 0;
    $result = array('start'=&gt;'', 'end'=&gt;'');
    foreach ($dates as $date) {
        $datetime = strtotime($date);
        if (!$i) $result['start'] = date('Y-m-d', $datetime). 'T00:00:00Z';
        if ($i == count($dates)-1) $result['end'] = date('Y-m-01', strtotime('1month', $datetime)). 'T00:00:00Z';
        $i ++;
    }
    return $result;
}</pre>]]></content:encoded>
</item>
<item>
	<title>使えそうなPHPのユーザー定義関数いろいろ</title>
	<link>http://dot-town-lab.com/laboratory/item/71</link>
	<description><![CDATA[今後使いそうな、PHPのユーザー定義関数をメモ。NULL値と空文字の判定NULLと空文字の場合のみtrueを返す関数。// 1:文字列function isNullEmpty($str) {    if ($str) return false;    $result = true;    if ($...]]></description>
	<author>Satoshi Mori</author>
	<category>PHP</category>
	<pubDate>Thu, 16 Jan 2014 12:40:43 +0900</pubDate>
	<content:encoded><![CDATA[<p>今後使いそうな、PHPのユーザー定義関数をメモ。</p>
<br>
<h4>NULL値と空文字の判定</h4>
<p>NULLと空文字の場合のみ<b>true</b>を返す関数。</p>
<pre>// 1:文字列
function isNullEmpty($str) {
    if ($str) return false;
    $result = true;
    if ($str === 0 || $str === '0') $result = false;
    return $result;
}</pre>
<br>
<h4>文字列を配列に分割する（マルチバイト対応）</h4>
<p>転載元：<a href="http://ameblo.jp/moekey/entry-10381298953.html" target="_blnk">マルチバイト文字列を１文字ずつ配列に格納｜適当に語ってみるﾃｽﾂ</a></p>
<pre>// 1:文字列, 2:文字コード
function mbStringToArray($sStr, $sEnc = 'UTF-8') {
    $aRes = array();
    while ($iLen = mb_strlen($sStr, $sEnc)) {
        array_push($aRes, mb_substr($sStr, 0, 1, $sEnc));
        $sStr = mb_substr($sStr, 1, $iLen, $sEnc);
    }
    return $aRes;
}</pre>
<br>
<h4>既存の日付かどうかをチャックする</h4>
<p>「2014-02-31」のような存在しない日付が指定された場合、その月の最終日を返す関数。</p>
<pre>// 1:日付（YYYY-MM-DD）
function getExistDate($date = null) {
    if (!$date) return null;
    $result = null;
    $date_time = strtotime($date);
    if ($date == date('Y-m-d', $date_time)) {
        $result = $date;
    } else {
        $result = date('Y-m-t', strtotime('-1month', $date_time));
    }
    return $result;
}</pre>
<br>
<h4>移動距離の度数を取得</h4>
<p>指定された座標からの移動距離を度数にして返す関数。</p>
<p>参考：<a href="http://blog.epitaph-t.com/?p=172" target="_blnk">なんとなく始めてみた、プログラマー雑記 &raquo; データベース内の緯度・経度を利用して半径500m以内を検索する方法</a></p>
<pre>// 1:緯度, 2:経度, 3:距離（メートル）
function getGeoMoveDistance($lat = 0, $lng = 0, $move = 100) {
    $earth_radius = 6356752.314; // 地球極半径
    $onedegree_second = 360 * 60 * 60; // 1秒
    $onesecond_degree = 1 / 60 / 60; // 1秒あたりの度数
    $lat_circle = $earth_radius * 2 * M_PI; // 円周（緯度）
    $lng_circle = $earth_radius * cos($lat / 180 * M_PI) * (2 * M_PI); // 円周（経度）
    return array(
        'latitude'=&gt;$onesecond_degree * ($move / ($lat_circle / $onedegree_second)),
        'longitude'=&gt;$onesecond_degree * ($move / ($lng_circle / $onedegree_second)),
    );
}</pre>]]></content:encoded>
</item>
<item>
	<title>JavaScriptで生成した要素をjQueryで操作するメモ</title>
	<link>http://dot-town-lab.com/laboratory/item/70</link>
	<description><![CDATA[append()した要素にclickイベントを設定する&lt;div id=&quot;hoge&quot;&gt;&lt;/div&gt;&lt;!--この中にspanタグを追加する--&gt;&lt;script type=&quot;text/javascript&quot;&gt;//&lt;![CDATA[    $(functio...]]></description>
	<author>Satoshi Mori</author>
	<category>jQuery</category>
	<pubDate>Wed, 15 Jan 2014 15:20:13 +0900</pubDate>
	<content:encoded><![CDATA[<h4>append()した要素にclickイベントを設定する</h4>
<pre>&lt;div id=&quot;hoge&quot;&gt;&lt;/div&gt;&lt;!--この中にspanタグを追加する--&gt;

&lt;script type=&quot;text/javascript&quot;&gt;
//&lt;![CDATA[
    $(function(){
        // 要素を作成
        var elm = $(document.createElement('span'));

        // 要素の内容を指定
        elm.html('SPANタグ');

        // 要素の属性を指定
        elm.attr({'data-number':1});

        // 要素を追加
        $('#hoge').append(elm);

        // イベントの設定
        elm.on('click', function(){
            console.log($(this).data('number'));
        });
    });
//]]&gt;
&lt;/script&gt;</pre>]]></content:encoded>
</item>
<item>
	<title>SVGのオブジェクトをjQueryを使ってアニメーションさせてみた</title>
	<link>http://dot-town-lab.com/laboratory/item/68</link>
	<description><![CDATA[HTML5からサポートされているInline SVG（インラインSVG）を、JavaScript (jQuery)を使っていろいろ試してみたのでメモしておきます。document.createElementNSSVGのオブジェクトを生成する場合は「document.crea...]]></description>
	<author>Satoshi Mori</author>
	<category>SVG</category>
	<pubDate>Thu, 18 Jul 2013 16:40:06 +0900</pubDate>
	<content:encoded><![CDATA[<p>HTML5からサポートされている<b>Inline SVG（インラインSVG）</b>を、JavaScript (jQuery)を使っていろいろ試してみたのでメモしておきます。</p>
<br>
<h4>document.createElementNS</h4>
<p>SVGのオブジェクトを生成する場合は「document.createElementNS」を使って生成する。</p>
<pre>var svgns = 'http://www.w3.org/2000/svg'; // SVGの名前空間
var svg = $(document.createElementNS(svgns, 'svg'));</pre>
<br>
<h4>svgタグはインライン要素</h4>
<p>Firefoxだとインライン要素の場合、オブジェクトの横幅が上手く取得できないので、ブロック要素にして取得する。</p>
<pre>var svgns = 'http://www.w3.org/2000/svg';
var svg = $(document.createElementNS(svgns, 'svg'));svg.appendTo($('div#hoge')); // div#hogeにSVGタグを追加svg.attr({width:'100%', height:100}); // SVGに幅と高さを指定svg.css('display', 'block'); // ブロック要素に変更console.log(svg.width());</pre>
<br>
<h4>参考サイト</h4>
<ul class="list_dot">
<li><a href="http://dotinstall.com/lessons/basic_svg" target="_blank">SVG入門 (全14回) - プログラミングならドットインストール</a></li>
<li><a href="http://kadoppe.com/archives/2012/01/svg-text%E3%81%AEtext-anchor%E5%B1%9E%E6%80%A7%E3%82%92%E3%81%A4%E3%81%8B%E3%81%A3%E3%81%A6%E3%81%BF%E3%81%9F%E3%80%82.html" target="_blank">SVG Textのtext-anchor属性をつかってみた。 | CreativeStyle</a></li><li><a href="http://www.h2.dion.ne.jp/~defghi/svgMemo/svgMemo_15.htm" target="_blank">svg要素の基本的な使い方まとめ</a></li>
<li><a href="http://d.hatena.ne.jp/ohnishiakira/20110715/1310738741" target="_blank">document.createElementNSの使い道 - おおにしあきらの日記</a></li>
<li><a href="http://d.hatena.ne.jp/ish-openspace/20070206/1170732556" target="_blank">span要素に対して指定したwidthがFirefoxでは無視される - ish-openspaceの日記</a></li>
</ul>]]></content:encoded>
</item>
<item>
	<title>CSSでデザインされた検索フォームを作成する</title>
	<link>http://dot-town-lab.com/laboratory/item/67</link>
	<description><![CDATA[下記の画像のような検索フォームを直ぐに実装できるよう、HTMLとCSSのコードをメモしておきます。レスポンシブデザインやリキッドデザインのサイトを想定して、横幅が可変するように設計しています。一応、IETest...]]></description>
	<author>Satoshi Mori</author>
	<category>CSS</category>
	<pubDate>Sat, 29 Jun 2013 15:10:58 +0900</pubDate>
	<content:encoded><![CDATA[<p>下記の画像のような検索フォームを直ぐに実装できるよう、HTMLとCSSのコードをメモしておきます。</p>
<p><img src="http://dot-town-lab.com/laboratory/images/news/files/201306/201306291249311.gif" /></p>
<br>
<p>レスポンシブデザインやリキッドデザインのサイトを想定して、横幅が可変するように設計しています。</p>
<p><b>一応、IETesterでIE7・IE8は確認しましたが、基本的にクロスブラウザを意識していないのでご注意ください。</b></p>
<br>
<h4>HTML</h4>
<pre>&lt;form action=&quot;/&quot; name=&quot;search&quot; method=&quot;get&quot;&gt;
    &lt;dl class=&quot;search&quot;&gt;        &lt;dt&gt;&lt;input type=&quot;text&quot; name=&quot;search&quot; value=&quot;&quot; placeholder=&quot;Search&quot; /&gt;&lt;/dt&gt;        &lt;dd&gt;&lt;button&gt;&lt;span&gt;&lt;/span&gt;&lt;/button&gt;&lt;/dd&gt;    &lt;/dl&gt;&lt;/form&gt;</pre>
<br>
<h4>CSS</h4>
<pre>dl.search{
    position:relative;    background-color:#fff;    border:1px solid #aaa;    -webkit-border-radius:6px;    -moz-border-radius:6px;    -o-border-radius:6px;    -ms-border-radius:6px;    border-radius:6px;}dl.search dt{    margin-right:40px;    padding:8px 0 8px 8px;}dl.search dt input{    width:100%;    height:24px;    line-height:24px;    background:none;    border:none;}dl.search dd{    position:absolute;    top:0;    right:0;}dl.search dd button{    display:block;    padding:10px;    background:none;    border:none;}dl.search dd button span{    display:block;    width:20px;    height:20px;    background:url('/images/search.png') no-repeat scroll 0 0;}</pre>]]></content:encoded>
</item>
<item>
	<title>HTML5のdata属性に配列やオブジェクトを格納してjQueryで取得する</title>
	<link>http://dot-town-lab.com/laboratory/item/66</link>
	<description><![CDATA[データの格納場所として便利なdata属性（独自データ属性）に、配列やオブジェクトを格納しておいて、jQueryで値を取得する方法をメモ。HTML属性の値を「'（シングルクォーテーション）」で囲む。配列やオブジェク...]]></description>
	<author>Satoshi Mori</author>
	<category>jQuery</category>
	<pubDate>Thu, 20 Jun 2013 15:49:31 +0900</pubDate>
	<content:encoded><![CDATA[<p>データの格納場所として便利なdata属性（独自データ属性）に、配列やオブジェクトを格納しておいて、jQueryで値を取得する方法をメモ。</p>
<br>
<h4>HTML</h4>
<p>属性の値を「'（シングルクォーテーション）」で囲む。</p>
<p>配列やオブジェクトの値で文字列を使用する場合は「"（ダブルクォーテーション）」で囲まないと、配列やオブジェクトが文字列として認識されてしまう。</p>
<pre>&lt;div id=&quot;arr&quot; date-arr='[1, 2, &quot;c&quot;]'&gt;
    配列の場合
&lt;/div&gt;
&lt;div id=&quot;obj&quot; date-obj='{&quot;a&quot;:1, &quot;b&quot;:2, &quot;c&quot;:&quot;c&quot;}'&gt;
    オブジェクトの場合
&lt;/div&gt;</pre>
<br>
<h4>JavaScript (jQuery)</h4>
<pre>var arr = $('#arr').data('arr');
var obj = $('#obj').data('obj');

console.log(arr[0]); // 出力：1
console.log(obj.c);  // 出力：c</pre>]]></content:encoded>
</item>
<item>
	<title>JavaScriptで日時を扱う時のメモ</title>
	<link>http://dot-town-lab.com/laboratory/item/65</link>
	<description><![CDATA[JavaScriptで時間の差や指定日時の何時間後などを求める事があったので、気になった所などを書き留めておこうと思います。1000ミリ秒PHPでタイムスタンプを取得した場合は秒形式の値が返されるけど、JavaScriptの...]]></description>
	<author>Satoshi Mori</author>
	<category>JavaScript</category>
	<pubDate>Fri, 31 May 2013 18:10:34 +0900</pubDate>
	<content:encoded><![CDATA[<p>JavaScriptで時間の差や指定日時の何時間後などを求める事があったので、気になった所などを書き留めておこうと思います。</p>
<br>
<h4>1000ミリ秒</h4>
<p>PHPでタイムスタンプを取得した場合は秒形式の値が返されるけど、JavaScriptの場合はミリ秒形式の値が返ってくる。</p>
<p>JavaScriptで時間を求める時は、「1秒 = 1000ミリ秒」の値を加えて計算する。</p>
<br>
<h4>Date.parse()</h4>
<p>日時の文字列を解析して、ミリ秒形式の値を返すメソッド。</p>
<p>ただし「2000-01-01 00:00:00」のように日付に「-」が使われている場合は、NaNを返すので、「2000/01/01 00:00:00」に置換してから利用する。</p>
<pre>var datetime = '2000-01-01 12:30:00';
var datetime_parse = datetime.replace(/-/g, '/'); // ハイフンをスラッシュに置換する
datetime_parse = Date.parse(datetime_parse); // ミリ秒形式の値に変換</pre>
<br>
<h4>date.setTime()</h4>
<p>Dateクラスのオブジェクトに、新たな時間を設定できるメソッド。</p>
<p>値を設定する場合は、setTime()の引数にミリ秒形式の値を設定して利用する。</p>
<pre>var d = new Date();
var datetime = '2000-01-01 12:30:00';
var datetime_parse = datetime.replace(/-/g, '/');
datetime_parse = Date.parse(datetime_parse);
d.setTime(datetime_parse); // datetimeの時間を設定</pre>
<br>
<h4>指定日時から20時間後の値を求める</h4>
<pre>var d = new Date()
    , one_sec = 1000 // 1秒
    , one_min = one_sec * 60 // 1分
    , one_hour = one_min * 60 // 1時間
    , datetime = '2000-01-01 08:45:50'
    , datetime_a = datetime.replace(/-/g, '/')
    , datetime_parse = Date.parse(datetime_a)
    , datetime_20h = datetime_parse + (one_hour * 20);
d.setTime(datetime_20h);
console.log(d);
/*
出力結果 : Sun Jan 02 2000 04:45:50 GMT+0900 (東京 (標準時))
*/</pre>
<br>
<h4>時間の差を求める</h4>
<pre>var one_sec = 1000 // 1秒
    , one_min = one_sec * 60 // 1分
    , one_hour = one_min * 60 // 1時間
    , datetime_a = '2000-01-01 08:45:50'
    , datetime_b = '2000-01-01 16:33:30';
datetime_a = datetime_a.replace(/-/g, '/');
datetime_b = datetime_b.replace(/-/g, '/');

var diff = Date.parse(datetime_b) - Date.parse(datetime_a)
    , diff_h = Math.floor(diff / one_hour) // 時間
    , diff_m = Math.floor(diff % one_hour / one_min) // 分
    , diff_s = Math.floor(diff % one_min / one_sec); // 秒
console.log(diff_h + '時間' + diff_m + '分' + diff_s + '秒');
/*
出力結果 : 7時間47分40秒
*/</pre>]]></content:encoded>
</item>
<item>
	<title>SQLを覚えよう::CASE式の使い方</title>
	<link>http://dot-town-lab.com/laboratory/item/63</link>
	<description><![CDATA[SQLには、switch文のように条件を書き分ける事が出来る、CASE式なるものがあるという事なので、試しに使ってみたので忘れないようメモしておきます。参考サイトCASE式のススメ下記のような「item」テーブルが存在...]]></description>
	<author>Satoshi Mori</author>
	<category>SQL</category>
	<pubDate>Mon, 27 May 2013 19:30:14 +0900</pubDate>
	<content:encoded><![CDATA[<p>SQLには、switch文のように条件を書き分ける事が出来る、CASE式なるものがあるという事なので、試しに使ってみたので忘れないようメモしておきます。</p>
<br>
<h4>参考サイト</h4>
<ul class="list_dot">
<li><a href="http://www.geocities.jp/mickindex/database/db_case.html" target="_blank">CASE式のススメ</a></li>
</ul>
<br>
<p>下記のような「item」テーブルが存在した場合の、CASE式を使ったSELECT文とUPDATE文のサンプルコードをメモ。</p>
<table class="list">
<thead><tr>
<th>id</th>
<th>name</th>
<th>price</th>
<th>ranking</th>
</tr></thead>
<tbody>
<tr><td class="a_right">1</td><td>りんご</td><td class="a_right">200</td><td class="a_right">4</td></tr>
<tr><td class="a_right">2</td><td>ゴリラ</td><td class="a_right">2000000</td><td class="a_right">99</td></tr>
<tr><td class="a_right">3</td><td>ラッパ</td><td class="a_right">30000</td><td class="a_right">5</td></tr>
<tr><td class="a_right">4</td><td>パンダ</td><td class="a_right">15000000</td><td class="a_right">2</td></tr>
<tr><td class="a_right">5</td><td>ダニ</td><td class="a_right">1</td><td class="a_right">99</td></tr>
<tr><td class="a_right">6</td><td>にぼし</td><td class="a_right">5</td><td class="a_right">1</td></tr>
<tr><td class="a_right">7</td><td>シリコン</td><td class="a_right">8500</td><td class="a_right">3</td></tr>
</tbody>
</table>
<br>
<h4>`price`の大きさに応じて変化する、`flag`カラムを追加したデータを取得するSQL</h4>
<pre>&lt;?php
$sql = 'SELECT `id`,`name`,`price`,`ranking`,'     . 'CASE'     . ' WHEN `price` &lt;= 10 THEN 1'     . ' WHEN `price` &gt; 10 AND `price` &lt;= 100 THEN 2'     . ' WHEN `price` &gt; 100 AND `price` &lt;= 1000 THEN 3'     . ' WHEN `price` &gt; 1000 AND `price` &lt;= 10000 THEN 4'     . ' WHEN `price` &gt; 10000 THEN 5'     . ' ELSE 0 END `flag` FROM `item`';?&gt;</pre>
<br>
<h4>特定のID以外の`ranking`に99を代入にして更新するSQL</h4>
<pre>&lt;?php
$sql = 'UPDATE `item` SET'     . ' `ranking` = CASE'     . ' WHEN `id` = 1 THEN 1' // りんご     . ' WHEN `id` = 6 THEN 2' // にぼし     . ' WHEN `id` = 3 THEN 3' // ラッパ     . ' WHEN `id` = 4 THEN 4' // パンダ     . ' WHEN `id` = 7 THEN 5' // シリコン     . ' ELSE 99 END'     . ' WHERE `price` &gt; 0';?&gt;</pre>]]></content:encoded>
</item>
<item>
	<title>Google Calendar API v3を利用して祝日を取得してみた</title>
	<link>http://dot-town-lab.com/laboratory/item/62</link>
	<description><![CDATA[カレンダーに祝日を表示する必要があり、Google CalendarのAPIを利用してみたのでメモしておきます。祝日を取得するなら、PEARのDate_Holidays_Japanを利用しても良かったんだけど、CakePHP内で利用するのが面倒...]]></description>
	<author>Satoshi Mori</author>
	<category>API</category>
	<pubDate>Sat, 30 Mar 2013 15:14:11 +0900</pubDate>
	<content:encoded><![CDATA[<p>カレンダーに祝日を表示する必要があり、Google CalendarのAPIを利用してみたのでメモしておきます。</p>
<p>祝日を取得するなら、PEARの<a href="http://pear.php.net/package/Date_Holidays_Japan/" target="_blank">Date_Holidays_Japan</a>を利用しても良かったんだけど、CakePHP内で利用するのが面倒そうだったので、Google Calendar APIを使ってみました。</p>
<br>
<p>まずは、Google Calendar APIを利用できるように下準備を</p>
<ul class="list_dot">
<li><a href="https://code.google.com/apis/console/" target="_blank">Google APIs Console</a>でCalendar APIのステータスをONにする</li>
<li>Google API keyを取得する</li>
<li>参考ページ（<a href="http://wiki.dobon.net/index.php?.NET%A5%D7%A5%ED%A5%B0%A5%E9%A5%DF%A5%F3%A5%B0%B8%A6%B5%E6%2F103" target="_blank">Googleカレンダーを使って祝日の情報を取得する - DoboWiki</a>）</li>
</ul>
<p><b>※参考ページでは、Google Calendar APIのバージョン2と3の取得方法が記載されているので、バージョン3を参考にしてください。</b></p>
<br>
<p>Google APIs Consoleで必要な設定を行ったら、お決まりのURLを入力すれば、JSONデータが返されるので取得完了です。</p>
<p>今回のサンプルコードは、PHPでの取得方法を記載しています。</p>
<pre>&lt;?php
// Google Calendar API v3 (Holiday)$holiday_type = urlencode('ja.japanese#holiday@group.v.calendar.google.com');$google_api_key = '{Google API Key}';$time_min = date('Y-m-01'). 'T00:00:00Z'; // RFC3339形式$time_max = date('Y-m-01', strtotime('1month')). 'T00:00:00Z';$google_holiday_jp_url = 'https://www.googleapis.com/calendar/v3/calendars/'. $holiday_type. '/events'    . '?key='. $google_api_key // Google API key    . '&amp;timeMin='. $time_min   // 取得開始日    . '&amp;timeMax='. $time_max   // 取得終了日（終了日の前日までしか取得しない）    . '&amp;maxResults=20'         // 取得数    . '&amp;orderBy=startTime'     // 並び順    . '&amp;singleEvents=true';    // ???$result = file_get_contents($google_holiday_jp_url);$result = json_decode($result);if (!empty($result-&gt;items)) {    foreach ($result-&gt;items as $value) {        $title = (string) $value-&gt;summary;        $date = (string) $value-&gt;start-&gt;date;        $holidays[$date] = $title;    }}?&gt;</pre>]]></content:encoded>
</item>
<item>
	<title>Smartyのテンプレート構文をDBに登録して使用する</title>
	<link>http://dot-town-lab.com/laboratory/item/61</link>
	<description><![CDATA[正直なところ利用価値もあんまり無さそうなんだけど、とりあえずメモしておく事に。タイトルだけだと、いまいちピンとこないので、一から順番に説明を。Smartyのテンプレート構文をDBに登録するSmartyのテンプレ...]]></description>
	<author>Satoshi Mori</author>
	<category>Smarty</category>
	<pubDate>Fri, 27 Jul 2012 09:00:00 +0900</pubDate>
	<content:encoded><![CDATA[<p>正直なところ利用価値もあんまり無さそうなんだけど、とりあえずメモしておく事に。</p>
<p>タイトルだけだと、いまいちピンとこないので、一から順番に説明を。</p>
<br>
<h4>Smartyのテンプレート構文をDBに登録する</h4>
<p>Smartyのテンプレート側で利用する、変数や関数を記入したテキストデータを登録しておく。</p>
<pre>&lt;?php
// 下記のようなテキストをDBに登録$tplval1 = '私は{$result.name}です。&lt;br /&gt;';$tplval2 = '年齢は{$result.age|number_format}歳です。';?&gt;</pre>
<br>
<h4>テンプレートファイルを書き換える</h4>
<p>変更可能なテンプレートファイルを用意して置いて、内容を上記のテキストデータに書き換える。</p>
<pre>&lt;?php
// ファイルデータを書き換える関数function outputTmp($file, $filepath, $value) {    $fp = fopen($url, &quot;w+&quot;);    $fw = fwrite($fp, $value);    fclose($fp);    return $file;}?&gt;</pre>
<br>
<h4>fetch()でテンプレートを出力する</h4>
<p>第3引数を指定しないと、前回と同じ内容のデータが返ってくる。</p>
<pre>&lt;?php
$smarty-&gt;assign(&quot;result&quot;, array( // Smarty変数定義    'name' =&gt; 'HOGE',    'age' =&gt; 9999,));$file = 'temp/output.tpl'; // TPLファイルの場所$filepath = $_SERVER['DOCUMENT_ROOT']. '/templates/'. $file; // ファイルパスecho '1. '. $smarty-&gt;fetch(outputTmp($file, $filepath, $tplval1), NULL, &quot;name&quot;);echo '2. '. $smarty-&gt;fetch(outputTmp($file, $filepath, $tplval2), NULL, &quot;age&quot;);/*出力 : 1. 私はHOGEです。出力 : 2. 年齢は9,999歳です。*/?&gt;</pre>
<br>
<p>テンプレートのテンプレートみたいになってるので、無意味な感じもしますが...。</p>
<p>まあ、ポジティブにみれば、FTPを使用せずに、Smartyの変数やら関数やらIF文やらが編集できるみたいな...。</p>]]></content:encoded>
</item>
<item>
	<title>アップロードした画像をPHPで保存するメモ</title>
	<link>http://dot-town-lab.com/laboratory/item/60</link>
	<description><![CDATA[画像ファイルのアップロードを試してみたので、その時のメモ。注意iPhone／iPad の場合は「input type=file」が対応してないので（正確にはSafariが、Opera Miniは対応している。）、別の方法を採るしかない。追...]]></description>
	<author>Satoshi Mori</author>
	<category>PHP</category>
	<pubDate>Mon, 11 Jun 2012 09:00:00 +0900</pubDate>
	<content:encoded><![CDATA[<p>画像ファイルのアップロードを試してみたので、その時のメモ。</p>
<br>
<h4>注意</h4>
<p>iPhone／iPad の場合は「input type=file」が対応してないので（正確にはSafariが、<a href="http://itunes.apple.com/jp/app/opera-mini-web-browser/id363729560?mt=8" target="_blank">Opera Mini</a>は対応している。）、<a href="http://www.1x1.jp/blog/2010/08/tips_for_upload_image_from_iphone_safari.html" target="_blank">別の方法</a>を採るしかない。</p>
<br>
<p>追記：iOS 6から「input type=file」が対応されている。</p>
<br>
<h4>enctype属性とMAX_FILE_SIZE</h4>
<p>ファイルのアップロードをする場合は、formタグにenctype属性を指定しないと、ファイルデータが送信されない。</p>
<p>MAX_FILE_SIZEを指定しておくとサイズオーバーの時、早い段階で処理を中断してくれるので長時間の処理待ちを防ぐ事ができます。ただし、MAX_FILE_SIZEを指定してもPHP側の最大サイズが変わる事はありません。</p>
<pre>&lt;form action=&quot;/&quot; method=&quot;post&quot; id=&quot;upload&quot; name=&quot;upload&quot; enctype=&quot;multipart/form-data&quot;&gt;
    &lt;!-- 1024 = 1KB --&gt;    &lt;input type=&quot;hidden&quot; name=&quot;MAX_FILE_SIZE&quot; value=&quot;1024&quot; /&gt;    &lt;input type=&quot;file&quot; name=&quot;upload_file&quot; /&gt;    &lt;input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;Upload&quot; /&gt;&lt;/form&gt;</pre>
<br>
<h4>送信されたデータを取得する</h4>
<p>送信されたファイルデータは「$_FILES」に格納される。「$_POST」じゃないので注意。</p>
<pre>&lt;?php
$file = $_FILES['upload_file'];$tmp_name = $file['tmp_name']; // 一時ファイルのパス?&gt;</pre>
<br>
<h4>ファイルデータを判別して画像リソースを取得する</h4>
<pre>&lt;?php
$tmp_size = getimagesize($tmp_name); // 一時ファイルの情報を取得$img = $extension = null;switch ($tmp_size[2]) { // 画像の種類を判別    case 1 : // GIF        $img = imageCreateFromGIF($tmp_name);        $extension = 'gif';        break;    case 2 : // JPEG        $img = imageCreateFromJPEG($tmp_name);        $extension = 'jpg';        break;    case 3 : // PNG        $img = imageCreateFromPNG($tmp_name);        $extension = 'png';        break;    default : break;}?&gt;</pre>
<br>
<h4>保存時のファイル名を作成する</h4>
<p>保存先に指定するディレクトリ（/upload）のパーミッションを「0744」または「0777」に変更しておく。</p>
<pre>&lt;?php
$save_dir = '/images/upload/';$save_filename = date('YmdHis');$save_basename = $save_filename. '.'. $extension;$save_path = $_SERVER[&quot;DOCUMENT_ROOT&quot;]. $save_dir. $save_basename;while (file_exists($save_path)) { // 同名ファイルがあればファイル名を変更する    $save_filename .= mt_rand(0, 9);    $save_basename = $save_filename. '.'. $extension;    $save_path = $_SERVER[&quot;DOCUMENT_ROOT&quot;]. $save_dir. $save_basename;}?&gt;</pre>
<br>
<h4>新しく画像データを作成する</h4>
<p>アップロードされたファイルをそのまま保存したくないので、画像リソースを元に画像のサイズを変更したデータを作成します。</p>
<pre>&lt;?php
$img_size = getImageSize($img, 500); // 最大500pxの画像サイズ$out = imageCreateTrueColor($img_size['w1'], $img_size['h1']); // 新しい画像データ// 画像サイズを変更する関数function getImageSize($img = null, $maxsize = 300) {    if (!$img) return false;    $w0 = $w1 = imageSx($img); // 画像リソースの幅    $h0 = $h1 = imageSy($img); // 画像リソースの高さ    if ($w0 &gt; $maxsize) { // $maxsize以下の大きさに変更する        $w1 = $maxsize;        $h1 = (int) $h0 * ($maxsize / $w0);    }    if ($h1 &gt; $maxsize) {        $w1 = (int) $w1 * ($maxsize / $h1);        $h1 = $maxsize;    }    return array(        'w0'=&gt;$w0, // 元画像の幅        'h0'=&gt;$h0, // 元画像の高さ        'w1'=&gt;$w1, // 保存画像の幅        'h1'=&gt;$h1, // 保存画像の高さ    );}?&gt;</pre>
<br>
<h4>新しい画像データにアップロードファイルの情報をコピーする</h4>
<pre>&lt;?php
// 背景色を設定する$color_white = imageColorAllocate($out, 255, 255, 255); // 色データを作成imageFill($out, 0, 0, $color_white);// $imgの画像情報を$outにコピーするimageCopyResampled(    $out, // コピー先    $img, // コピー元    0, 0, 0, 0, // 座標（コピー先:x, コピー先:y, コピー元:x, コピー元:y）    $img_size['w1'], $img_size['h1'], $img_size['w0'], $img_size['h0'] // サイズ（コピー先:幅, コピー先:高さ, コピー元:幅, コピー元:高さ）);?&gt;</pre>
<br>
<h4>新しい画像データを保存する</h4>
<pre>&lt;?php
saveImage($out, $save_path, $extension);// 画像を保存する関数function saveImage($img = null, $file = null, $ext = null) {    if (!$img || !$file || !$ext) return false;    switch ($ext) {        case &quot;jpg&quot; :            $result = imageJPEG($img, $file);            break;        case &quot;gif&quot; :            $result = imageGIF($img, $file);            break;        case &quot;png&quot; :            $result = imagePNG($img, $file);            break;        default : return false; break;    }    chmod($file, 0644); // パーミッション変更    return $result;}?&gt;</pre>]]></content:encoded>
</item>
<item>
	<title>PHPでデータをエクセルで出力する。</title>
	<link>http://dot-town-lab.com/laboratory/item/58</link>
	<description><![CDATA[今まで、データベースのデータなどをエクセルに出力する時は、PEARのSpreadsheet_Excel_Writerを使用していたんですが、今の時代ちょっとキツイよねっていうことで、別のライブラリ（Excel_Reviser）を試したので...]]></description>
	<author><br />
<b>Notice</b>:  Undefined index: 0 in <b>/home/dot-town/dot-town-lab.com/public_html/laboratory/views/rss.html</b> on line <b>30</b><br />
</author>
	<category>PHP</category>
	<pubDate>Fri, 03 Feb 2012 09:00:00 +0900</pubDate>
	<content:encoded><![CDATA[<p>今まで、データベースのデータなどをエクセルに出力する時は、PEARの<a href="http://pear.php.net/manual/ja/package.fileformats.spreadsheet-excel-writer.intro.php" target="_blank">Spreadsheet_Excel_Writer</a>を使用していたんですが、今の時代ちょっとキツイよねっていうことで、別のライブラリ（<a href="http://chazuke.com/?page_id=126" target="_blank">Excel_Reviser</a>）を試したのでメモ。</p>
<br>
<h4>Spreadsheet_Excel_Writer</h4>
<ul class="list_dot">
<li>PEARライブラリなので有名</li>
<li>BIFF5（Excel95）に対応</li>
<li>BIFF8（Excel97～2003）は、<a href="http://d.hatena.ne.jp/kent013/20080205/1202209327" target="_blank">パッチ</a>をすれば対応できるらしい</li>
</ul>
<br>
<h4>Excel_Reviser</h4>
<ul class="list_dot">
<li>日本の方が製作したので日本語対応（良）</li>
<li>BIFF8（Excel97～2003）に対応</li>
<li>PHP4.4.1以降 PHP5.1.1以降に対応</li>
</ul>]]></content:encoded>
</item>
<item>
	<title>以前書いていたブログの記事を移植しました。</title>
	<link>http://dot-town-lab.com/laboratory/item/57</link>
	<description><![CDATA[今のブログを開設する前に、やっていたブログをサーバーから削除しようと思ったので、記事を移植しました。Flash記事ばっかりで、2、3年前の記事なので役に立つかどうか分からないけど、もったいないので...。移...]]></description>
	<author>Satoshi Mori</author>
	<category>メモ</category>
	<pubDate>Fri, 06 Jan 2012 09:00:00 +0900</pubDate>
	<content:encoded><![CDATA[<p>今のブログを開設する前に、やっていたブログをサーバーから削除しようと思ったので、記事を移植しました。</p>
<p>Flash記事ばっかりで、2、3年前の記事なので役に立つかどうか分からないけど、もったいないので...。</p>
<br>
<h4>移植リスト</h4>
<ul class="list_dot">
<li><a href="/laboratory/item/56">スラローム？</a></li>
<li><a href="/laboratory/item/55">タイピングゲーム</a></li>
<li><a href="/laboratory/item/54">形状記憶スライム</a></li>
<li><a href="/laboratory/item/53">お絵描き</a></li>
<li><a href="/laboratory/item/52">AIRをやってみよう</a></li>
<li><a href="/laboratory/item/51">忘れやすい自分に対してのメモ - その 1（クロスドメイン）-</a></li>
<li><a href="/laboratory/item/50">SoundMixer.computeSpectrumの問題点</a></li>
<li><a href="/laboratory/item/49">サウンドイコライザ</a></li>
<li><a href="/laboratory/item/48">波打つMC</a></li>
<li><a href="/laboratory/item/47">Soundの処理</a></li>
<li><a href="/laboratory/item/46">色とりどりに（2）>>続き</a></li>
<li><a href="/laboratory/item/45">色とりどりに（2）</a></li>
<li><a href="/laboratory/item/44">花火</a></li>
<li><a href="/laboratory/item/43">文字を順番に</a></li>
<li><a href="/laboratory/item/42">色とりどりに</a></li>
<li><a href="/laboratory/item/41">オセロのクラス化</a></li>
<li><a href="/laboratory/item/40">ゴム？</a></li>
<li><a href="/laboratory/item/39">とりえずASクラスを使ってみる</a></li>
</ul>]]></content:encoded>
</item>
<item>
	<title>Google+ APIを使ってみた（JavaScript編）</title>
	<link>http://dot-town-lab.com/laboratory/item/38</link>
	<description><![CDATA[「Google+ APIを使ってみた」の最終章として、JavaScript編をメモしておく事に。今までのメモは、下記のリンクを参照。Google+ APIを使ってみた（下準備編）Google+ APIを使ってみた（PHP編）Google+ APIを使って...]]></description>
	<author>Satoshi Mori</author>
	<category>API</category>
	<pubDate>Thu, 29 Dec 2011 09:00:00 +0900</pubDate>
	<content:encoded><![CDATA[<p>「Google+ APIを使ってみた」の最終章として、JavaScript編をメモしておく事に。今までのメモは、下記のリンクを参照。</p>
<ul class="list_num">
<li><a href="/laboratory/item/35">Google+ APIを使ってみた（下準備編）</a></li>
<li><a href="/laboratory/item/37">Google+ APIを使ってみた（PHP編）</a></li>
<li>Google+ APIを使ってみた（JavaScript編）</li>
</ul>
<br>
<p>今回の「JavaScript編」はSNS系のサイトによくある、下の方までスクロールしたら次の記事を読み込んで表示する処理をメモしておきます。</p>
<br>
<h4>用意するモノと参考にしたモノ</h4>
<ul class="list_dot">
<li>JSONデータ（<a href="/laboratory/item/37">前回書いた記事</a>で作成した配列をJSON形式で出力）</li>
<li>jQuery</li>
<li><a href="http://kachibito.net/web-design/scrolling-dynamic-js.html" target="_blank">ボックス内をスクロールすると自動でコンテンツをロードするjQuery - かちびと. net</a>（参考サイト）</li>
<li><a href="http://ken.quoit.jp/2010/05/27/%E3%83%9C%E3%83%83%E3%82%AF%E3%82%B9%E5%86%85%E3%82%92%E3%82%B9%E3%82%AF%E3%83%AD%E3%83%BC%E3%83%AB%E3%81%99%E3%82%8B%E3%81%A8%E8%87%AA%E5%8B%95%E3%81%A7%E3%82%B3%E3%83%B3%E3%83%86%E3%83%B3%E3%83%84/" target="_blank">ボックス内をスクロールすると自動でコンテンツをロードするjQueryをちょっと変えてみた | QUOIT Blog</a>（参考サイト）</li>
</ul>
<br>
<h4>HTML</h4>
<p>HTML5でサポートされた、data属性を利用するコードに修正<small class="col_999">（2013/07/24）</small>しました。</p>
<p>「data-nextpage」には、Google+ APIから取得できる<b>”nextPageToken”</b>を代入する。</p>
<p>「data-url」には、Google+ APIのデータを取得出来るURLを代入する。<a href="/laboratory/item/37">前回の記事</a>で加工したデータを利用する。</p>
<pre>&lt;div id=&quot;googleplus&quot; data-nextpage=&quot;&quot; data-url=&quot;/ajax/googleplus.php&quot;&gt;
    &lt;!-- この中に記事を挿入していく --&gt;
&lt;/div&gt;</pre>
<br>
<h4>scrolloader.js</h4>
<p>ページの残りが、一定の高さより下回ったら、$.ajax()で次のデータを取得するオブジェクト。</p>
<pre>/*
 * スクロールで自動ロードをするオブジェクト
 */
var scrolloader = function (options) {
    var t = this;
    options = options ? options : {};

    t.isloader = false; // ロード判定
    t.iniload = options.iniload ? true : false; // 初期ロードの有無
    t.offset = !isNaN(options.offset) ? options.offset : 300; // ロードを行う基準値
    t.nextpage = '';
    t.url = '';
    t.target = options.target ? options.target : $('#scrolloader'); // データを追加するコンテンツ
    t.window = options.window ? options.window : $(window); // スクロールするコンテンツ
    t.document = options.document ? options.document : $(document); // スクロール内のコンテンツ
    t.customhtml = typeof options.customhtml == 'function' ? options.customhtml : null;

    t.initial();
};
scrolloader.prototype = {
    initial : function () { // 初期設定
        if (!this.target.size()) return false;
        if (this.iniload) this.load(true);
    },
    scroll : function () { // スクロール時の設定
        if (!this.target.size()) return false;
        if (this.offset &gt; this.getRestHeight()) {
            this.load(false);
        }
    },
    load : function (init) { // データ読込
        var t = this;
        if (t.isloader) return false; // ロード判定がTRUEの場合は処理をしない
        var target = t.target;
        t.nextpage = target.data('nextpage');
        t.url = target.data('url');

        // &quot;nextpage&quot;が存在する場合と、&quot;init&quot;がTRUE場合のみ処理をする
        if (t.nextpage || init) {
            t.isloader = true; // ロード判定をTRUEにする
            $.ajax({
                type : 'post',
                dataType : 'json',
                url : t.url,
                data : {nextpage:encodeURIComponent(t.nextpage)},
                timeout : 10000,
                error : function () {
                    console.log('File Load Error.');
                },
                success : function (obj) {
                    var html = t.getHtml(obj.items);
                    if (html) {
                        target.append(html);
                        target.data('nextpage', obj.nextpage); // &quot;nextpage&quot;を更新
                        t.isloader = false; // ロード判定をFALSEにする
                    } else {
                        console.log('Data Error.');
                    }
                }
            });
        }
    },
    getHtml : function (data) { // HTML取得
        if (!data) return false;
        if (this.customhtml) return this.customhtml(data);
        var html = '';
        for (var i = 0; i &lt; data.length; i++) {
            html += '&lt;dl&gt;\
                &lt;dt&gt;' + data[i].title + '&lt;/dt&gt;\
                &lt;dd&gt;' + data[i].description + '&lt;/dd&gt;\
                &lt;/dl&gt;';
        }
        return html;
    },
    getRestHeight : function () { // ページの残りを取得
        var scroll = this.window.scrollTop(); // スクロールした距離
        var winH = this.window.height(); // ウィンドウ（表示領域）の高さ
        var docH = this.document.height(); // ページ（全体）の高さ
        return docH - (winH + scroll);
    }
};</pre>
<br>
<h4>scrolloader.jsを実行する</h4>
<p>HTMLの読込完了時に”scrolloader”のオブジェクトを生成する。初期値を設定できるので、変更したい値がある場合は指定する。</p>
<p>スクロールイベント時に”scrolloader”のスクロール関数を実行させる。</p>
<pre>/*
 * 読込完了時
 */
var sl = null;
$(function(){
    sl = new scrolloader({
        target : $('#googleplus'),
        iniload : true, // 初期ロード有り
        offset : 100, // 残りが100pxを下回ったら実行する
        customhtml : function (data) { // カスタムHTMLを設定
            var html = '';
            for (var i = 0; i &lt; data.length; i++) {
                html += '&lt;dl&gt;\
                    &lt;dt&gt;' + data[i].item_title + '&lt;/dt&gt;\
                    &lt;dd&gt;' + data[i].item_content + '&lt;/dd&gt;\
                    &lt;/dl&gt;';
            }
            return html;
        }
    });
});

/*
 * スクロール時
 */
$(window).scroll(function(){
    sl.scroll();
});
</pre>]]></content:encoded>
</item>
<item>
	<title>Google+ APIを使ってみた（PHP編）</title>
	<link>http://dot-town-lab.com/laboratory/item/37</link>
	<description><![CDATA[前回書いた「Google+ APIを使ってみた（下準備編）」の続きとして、今回はPHP編集編をメモ。Google+ APIを使ってみた（下準備編）Google+ APIを使ってみた（PHP編）Google+ APIを使ってみた（JavaScript編）Googl...]]></description>
	<author>Satoshi Mori</author>
	<category>API</category>
	<pubDate>Fri, 16 Dec 2011 09:00:00 +0900</pubDate>
	<content:encoded><![CDATA[<p>前回書いた「<a href="/laboratory/item/35">Google+ APIを使ってみた（下準備編）</a>」の続きとして、今回はPHP編集編をメモ。</p>
<ul class="list_num">
<li><a href="/laboratory/item/35">Google+ APIを使ってみた（下準備編）</a></li>
<li>Google+ APIを使ってみた（PHP編）</li>
<li><a href="/laboratory/item/38">Google+ APIを使ってみた（JavaScript編）</a></li>
</ul>
<br>
<p>Google+に登録した共有記事を取得するには、特定のURLを打ち込めば「JSON形式」で返してくれるので、別にPHPを使わなくてもいいんだけど、項目数が多いので必要最低限の情報を取得して加工する事に。</p>
<br>
<h4>Google+ APIの共有記事を取得するURL</h4>
<p>リクエストしたデータに”nextPageToken”という値があるので、その値を”pageToken”に指定する事ができます。</p>
<pre>&lt;?php
// URLのパラメータ
$user_id = 'XXXXXXXXXXXXXXXXXXXXX'; // [必須] Google+のID（Google+のURLにある10桁以上の数値）
$max_result = 10; // 読込記事の数（初期値20、1～100まで指定可能）
$page_token = ''; // 読込記事の位置（指定しなかった場合は、最新記事から取得する）
$api_key = 'XXXXXXXXXXXXXXXXXXXXX'; // [必須] Google API key（Google apisで取得する）

$url = 'https://www.googleapis.com/plus/v1/people/'. $user_id. '/activities/public'
    . '?maxResults='. $max_result
    . '&amp;pageToken='. $page_token
    . '&amp;key='. $api_key;
?&gt;</pre>
<br>
<h4>データの取得と加工</h4>
<p>値をそのまま利用すると、オブジェクトとして認識される場合があるので、型キャストを行って文字列に変換しています。</p>
<pre>&lt;?php
// データ取得
$data = file_get_contents($url);
$data = json_decode($data); // オブジェクトに変換（PHP5.2以上で利用可）

// データ加工
$result = array('nextpage'=&gt;'', 'items'=&gt;array());
if (count($data-&gt;items)) {
    $result['nextpage'] = $data-&gt;nextPageToken; // 前の記事を読み込む時に使用する

    foreach ($data-&gt;items as $key =&gt; $value) {
        $result['items'][] = array(
            'url'          =&gt; (string) $value-&gt;url, // Google+個別記事のURL
            'actor_name'   =&gt; (string) $value-&gt;actor-&gt;displayName, // Google+登録者名
            'actor_url'    =&gt; (string) $value-&gt;actor-&gt;url, // // Google+登録者URL
            'actor_img'    =&gt; (string) $value-&gt;actor-&gt;image-&gt;url, // Google+登録者画像URL
            'item_url'     =&gt; (string) $value-&gt;object-&gt;url, // Google+個別記事のURL（urlと同じ?）
            'item_title'   =&gt; (string) $value-&gt;object-&gt;attachments[0]-&gt;displayName, // 記事タイトル
            'item_content' =&gt; (string) $value-&gt;object-&gt;attachments[0]-&gt;content, // 記事内容
            'item_link'    =&gt; (string) $value-&gt;object-&gt;attachments[0]-&gt;url, // 元記事URL
            'item_img'     =&gt; (string) $value-&gt;object-&gt;attachments[0]-&gt;fullImage-&gt;url, // 記事画像URL
            'item_img2'    =&gt; (string) $value-&gt;object-&gt;attachments[0]-&gt;image-&gt;url, // 記事画像(小)URL
            'datetime'     =&gt; date(&quot;Y-m-d H:i:s&quot;, strtotime($value-&gt;published)), // 登録日
        );
    }
}
?&gt;</pre>
<br>
<h4>JSONデータとして出力</h4>
<p>PHPでJSONデータを扱う場合は、PHPのバージョンを5.2以上にしておくと「json_encode」と「json_decode」が使えるので便利です。</p>
<p>PHP5.1以下の場合は、PEARの「<a href="http://pear.php.net/package/Services_JSON" target="_blank">Services_JSON</a>」を利用してください。</p>
<pre>&lt;?php
// JSONのHTTPヘッダを指定して出力
header(&quot;Content-Type: text/javascript; charset=utf-8&quot;);
echo json_encode($result);
exit();
?&gt;</pre>]]></content:encoded>
</item>
<item>
	<title>IE7のバグ？CSSで input[size="20"]{} を使用したら。</title>
	<link>http://dot-town-lab.com/laboratory/item/36</link>
	<description><![CDATA[IETesterやSpoon Browser Sandboxなどのテストブラウザーでしか確認していないので、本当にそうなるかどうかは分からないけど、IE7で今までにない現象が起きたのでメモしておきます。とあるサイトを作成中にチェ...]]></description>
	<author>Satoshi Mori</author>
	<category>CSS</category>
	<pubDate>Wed, 14 Dec 2011 09:00:00 +0900</pubDate>
	<content:encoded><![CDATA[<p>IETesterやSpoon Browser Sandboxなどのテストブラウザーでしか確認していないので、本当にそうなるかどうかは分からないけど、IE7で今までにない現象が起きたのでメモしておきます。</p>
<br>
<ul class="list_num">
<li>とあるサイトを作成中にチェックボックス・ラジオボタン・インプットイメージの横幅が、IE7だけ異常な事に気づく。</li>
<li>IETesterのバグだと思い放置。</li>
<li>サイト完成間近で、やっぱり気になるのでSpoon Browser Sandboxで確認してみるとIETesterと同じだった。</li>
<li>混じりっけ無しのinputタグだったので、CSSを検証してみる事に。</li>
<li>原因判明：dt input[size="20"]{width:200px;}</li>
<li>ここの記述が原因で、横幅が異常だった。</li>
<li>なんで？って感じだけど、試しにsizeの値を変えたら直った。</li>
<li>問題解決：dt input[size="18"]{width:200px;}</li>
</ul>
<br>
<p>なぜこんな事が起こったのかは分からないけど、とりあえず次からは「input[size="20"]{}」は使わないでおこう。</p>]]></content:encoded>
</item>
</channel>
</rss>