1. 単純な配列を初期化
var a = ["abc", "def"];
2. 連想配列(オブジェクト)を初期化
var a = {"a":"abc", "b":"def"};
しがないプログラマーの愚痴です^^; # 仕事の覚え書きか?
var a = ["abc", "def"];
var a = {"a":"abc", "b":"def"};
//====================================================================
//! タグの属性をパースする
//! 属性名はアルファベット, 記号(-_), 数字を認めます。
//! 値は "' での括りを認めます。
//! @param string $str タグの属性文字列
//! 例 type=submit type="submit" type='submit' checked
//! @return array キーが属性名の配列
//====================================================================
function aryParseTagAttribute( $str )
{
//=== 正規表現 ===================================================
// $ma の要素番号
// 1 2 34 5 67 8 9
$re = <<<_EOL_
/\s*([A-Za-z0-9_\-]+)(=(([^"'][^\s]*[^"'])|('(([^'\\\\]|\\\\.)*)')|("(([^"\\\\]|\\\\.)*)")))?/
_EOL_;
$iMatches = preg_match_all( $re, $str, $ma );
$aryAttr = array( );
for ( $i = 0; $i < $iMatches; ++ $i )
{
//=== 属性名 =================================================
$strName = $ma[1][$i];
//=== 値を取得 ===========================================
// type="submit"
// $ma[] は (かっこの順にサブ文字列を格納している
if ( !empty( $ma[4][$i] ) )
$strValue = $ma[4][$i]; // 括り無し
else if ( !empty( $ma[6][$i] ) )
$strValue = $ma[6][$i]; // '' 括り
elseif ( !empty( $ma[9][$i] ) )
$strValue = $ma[9][$i]; // "" 括り
else
$strValue = ''; // 値なし
//============================================================
$aryAttr[$strName] = $strValue;
}
//================================================================
return $aryAttr;
}
$s = <<<_EOL_ type="text" name='DATE' onclick="func( '\"test\"' ); return" width=100 _EOL_; $a = aryParseTagAttribute( $s ); print_r( $a );
Array
(
[type] => text
[name] => DATE
[onclick] => func( '\"test\"' ); return
[width] => 100
)
例: <img src="http://maps.google.co.jp/maps/api/staticmap?center=東京都青梅市&zoom=18&size=640x400&maptype=roadmap&sensor=false&markers=color:red|label:A|東京都青梅市" />
function OnLoad( )
{
var latlng;
var strAddress = "東京都青梅市東青梅1-7-7";
var geocoder = new google.maps.Geocoder();
geocoder.geocode
(
{
'address': strAddress
}
, function( results, status )
{
if ( status != google.maps.GeocoderStatus.OK )
{
Debug( "status=" + status );
return;
}
latlng = results[0].geometry.location;
// 地図を作成
var map = new google.maps.Map
(
document.getElementById("map_canvas")
, {
zoom: 15,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
);
// マーカーを作成
var marker = new google.maps.Marker( { positon: latlng, map: map } );
var marker = new google.maps.Marker
(
{
position: latlng
, map: map
, title: "(株)クレアンスメアード"
}
);
// ポップアップ設定
var infowindow = new google.maps.InfoWindow
(
{
content: '(株)クレアンスメアード<br>0428-23-3120<br>'
, size: new google.maps.Size( 450, 150 )
}
);
google.maps.event.addListener
(
marker
, 'click'
, function( )
{
infowindow.open( map, marker );
}
);
}
);
}
$a = array( 1, 2, 3 ); foreach ( $a as &$i ) echo $i; echo ','; foreach ( $a as $i ) echo $i;
123,122となります。
// Context の取得
Context context = this.getBaseContext( );
CamLog.Debug( "context = " + context.toString( ) );
// WindowManager の取得
WindowManager wm = (WindowManager)context.getSystemService( Context.WINDOW_SERVICE );
CamLog.Debug( "wm = " + wm.toString( ) );
// DisplayMetrics の取得
DisplayMetrics objMetrics = new DisplayMetrics( );
wm.getDefaultDisplay( ).getMetrics( objMetrics );
CamLog.Debug( "metrics = " + objMetrics.toString( ) );
CamLog.Debug( "scaledDensity = " + objMetrics.scaledDensity );
// 通常フォントサイズの取得
// fPixel * Metrics#scaledDensity = fDip
// fPixel = fDip / Metrics#scaledDensity
m_fFontSizeThis = FONT_SIZE_THIS / objMetrics.scaledDensity;
m_fFontSizeOther = FONT_SIZE_OTHER / objMetrics.scaledDensity;