Monthly Archives: 2月 2017

「PHP入門」ボタンでajax通信を行うサンプルコード

1.html画面
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv=”Content-type” content=”text/html; charset=utf-8″>
<script type=”text/javascript” src=”http://code.jquery.com/jquery-1.8.2.min.js”></script>
<script type=”text/javascript”>
$(function(){
//ボタンをクリック
$(“#changeAjax”).click(function(){
//Ajax処理
var html = $.ajax({
type: “POST”,
url: “employeeAdd.php”,
data: “name=oosaki&employeeid=34”,
async: false
}).responseText;
$(“#cftDiv”).html(‘<h2>’+html+'</h2>’);
});
});
</script>
</head>
<body>
<div id=”cftDiv”><h2>ajaxでテキストを変更</h2></div>
<button id=”changeAjax” type=”button”>ajaxでコンテンツを変更</button>
</body>
</html>
2.employeeAdd.php
<?php
$msg=’こんにちは,’.$_POST[‘name’].’,番号 ‘.$_POST[’employeeid’];
echo $msg;
?>

「Openlayers入門」Featureの使い方のメモ

1.selectFeatureクラスの作成
var select_feature_control=new Openlayers.Control.SelectFeature(vector_layer,{
multiple:false,
toggle:true,
multipleKey:’shiftKey’
});
map.addControl(select_feature_control);
select_feature_control.activate();

2.featureselectedイベント関数の定義
function select_feature(event){
document.getElmentById(‘map_feature_log’).innerHTML=”;
//Show the current selected feature (passed in from the
event object)
var display_text = ‘Clicked on: ‘
+ ‘<strong>’ + event.feature.attributes.location + ‘</
strong>’
+ ‘: ‘ + event.feature.attributes.description + ‘<hr
/>’;
document.getElementById(‘map_feature_log’).innerHTML =
display_text;

//Show all the selected features
document.getElementById(‘map_feature_log’).innerHTML += ‘All
selected features: ‘;
//Now, loop through the selected feature array
for(var i=0; i<vector_layer.selectedFeatures.length; i++){
document.getElementById(‘map_feature_log’).innerHTML
+=
vector_layer.selectedFeatures[i].attributes.
location + ‘ | ‘;
}
}
}

3.イベントの登録
vector_layer.events.register(‘featureselected’,this,selected_feature);

「ios開発」デバイスとアプリに関する情報を取得サンプル

サンプルコード:

//デバイスに関する情報
NSString *strName = [[UIDevice currentDevice] name];
NSLog(@”デバイス名:%@”, strName);
NSString *strId = [[UIDevice currentDevice] uniqueIdentifier];

NSString *strSysName = [[UIDevice currentDevice] systemName];
NSLog(@”システム名:%@”, strSysName);// e.g. @”iOS”
NSString *strSysVersion = [[UIDevice currentDevice] systemVersion];
NSLog(@”システムバージョン:%@”, strSysVersion);// e.g. @”6.0″
NSString *strModel = [[UIDevice currentDevice] model];
NSLog(@”デバイスモード:%@”, strModel);// e.g. @”iPhone”, @”iPod touch”
NSString *strLocModel = [[UIDevice currentDevice] localizedModel];
NSLog(@”ローカルデバイスモード:%@”, strLocModel);// localized version of model

//appに関する情報
NSDictionary *dicInfo = [[NSBundle mainBundle] infoDictionary];

// CFShow(dicInfo);
NSString *strAppName = [dicInfo objectForKey:@”CFBundleDisplayName”];
NSLog(@”App名:%@”, strAppName);
NSString *strAppVersion = [dicInfo objectForKey:@”CFBundleShortVersionString”];
NSLog(@”Appバージョン:%@”, strAppVersion);
NSString *strAppBuild = [dicInfo objectForKey:@”CFBundleVersion”];
NSLog(@”AppのBuildバージョン:%@”, strAppBuild);

//ユーザーの言語を取得する
NSArray *languageArray = [NSLocale preferredLanguages];
NSString *language = [languageArray objectAtIndex:0];
NSLog(@”言語:%@”, language);//en
NSLocale *locale = [NSLocale currentLocale];
NSString *country = [locale localeIdentifier];
NSLog(@”国:%@”, country); //en_US

//画面サイズ
CGRect rect = [[UIScreen mainScreen] bounds];
CGSize size = rect.size;
CGFloat width = size.width;
CGFloat height = size.height;
NSLog(@”幅、高:%f,%f”,width,height);

//解像度
CGFloat scale_screen = [UIScreen mainScreen].scale;
NSLog(@”screen w:%f”,width*scale_screen);
NSLog(@”screen h:%f”,height*scale_screen);

「Java開発]MongoDBを操作(insert、update、delete、検索)する方法

Javaコード:
private static void mongoCftTest(){
try {

Mongo m = new Mongo( “172.17.2.201” , 27017 );
DB db = m.getDB( “cftdb” );

//collectionの作成
DBCollection collection = db.getCollection(“demoCollectionDemo”);

BasicDBObject doc = new BasicDBObject();
doc.put(“name”, “MongoDB”);
doc.put(“type”, “database”);
doc.put(“count”, 1);

BasicDBObject info = new BasicDBObject();
info.put(“x”, 203);
info.put(“y”, 102);
doc.put(“info”, info);

//複数のレコードを挿入
for (int i=0; i < 100; i++) {
collection.insert(new BasicDBObject().append(“i”, i));
}

//レコード数を取得
System.out.println(collection.getCount());

//Cursorで全てのドキュメントを取得
DBCursor cursor = collection.find();
try {
while(cursor.hasNext()) {
System.out.println(cursor.next());
}
} finally {
cursor.close();
}

BasicDBObject query = new BasicDBObject();
query.put(“i”, 56);
cursor = collection.find(query);
try {
while(cursor.hasNext()) {
System.out.println(cursor.next());
}
} finally {
cursor.close();
}

//検索条件 i>80
query = new BasicDBObject();
query.put(“i”, new BasicDBObject(“$gt”, 80)); // find all where i > 80
cursor = collection.find(query);
try {
while(cursor.hasNext()) {
System.out.println(cursor.next());
}
} finally {
cursor.close();
}

//更新条件i=56
query = new BasicDBObject();
query.put(“i”, 56);
BasicDBObject update = new BasicDBObject();
update.put(“i”, 560);
DBObject dbobj = collection.findAndModify(query, update);
System.out.println(dbobj);

//削除条件i=74
query = new BasicDBObject();
query.put(“i”, 74);
collection.findAndRemove(query);

// indexの作成
collection.createIndex(new BasicDBObject(“i”, 1)); // create index on “i”, ascending

//indexのリストを取得
List<DBObject> list = collection.getIndexInfo();
for (DBObject o : list) {
System.out.println(o);
}

//データベースリスト
for (String s : m.getDatabaseNames()) {
System.out.println(s);
}
//collectionリスト
Set<String> colls = db.getCollectionNames();
for (String s : colls) {
System.out.println(s);
}

//データベース削除
//m.dropDatabase(“my_new_db”);

} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

jQuery入門–ready(fn)の使い方

サンプルコード:
jQuery(function(){});
jQuery().ready(function(){});
jQuery(‘#temp’).click(function() {});

$(document).ready(function(){
$(“p”).click(function(){
$(this).hide();
});
});

JavaScriptでsetTimeoutを使うサンプルコード

JavaScriptコード:
<input type=”button” id=”smsauth-btn” class=”smsauth-btn” value=”認証コード”/>
var t = 120;
showT(t);
function showT(t) {
if(t > 0){
$(“.smsauth-btn”).val(t +”秒”);
setTimeout(function(){showT(t-1)},1000)
//setTimeout(showT(t-1),5000)
//$(‘.smsauth-btn’).attr(“disabled”,true);
}else{
$(“.smsauth-btn”).val(“SMS認証”);
//$(“.smsauth-btn”).removeAttr(“disabled”);
}
}

「PHP入門」文字列を反転する方法まとめ

$str = “study it in this site”;
方法1
print_r(strrev($str));

方法2
$newArrFirst = [];
$newStrFirst = ”;
$newArrFirst = str_split($str);
$arrCount = count($newArrFirst);
for ($i=0; $i < $arrCount; $i++) {
$newStrFirst.=$newArrFirst[$i];
}
echo “<pre>”;
print_r($newStrFirst);
echo “</pre>”;

方法3
$newStrSecond = ”;
$arrCountSecond = strlen($str);
for ($i=1; $i <= $arrCountSecond; $i++) {
$newStrSecond.=substr($str, -$i, 1);
}
echo “<pre>”;
print_r($newStrSecond).”\n”;
echo “</pre>”;

方法4
$newStrThird = ”;
$arrCountThird = strlen($str);
for ($i = $arrCountThird; $i>=0;$i–) {
@$newStrThird.=$str[$i];
}
echo “<pre>”;
print_r($newStrThird).”\n”;
echo “</pre>”;

PHPでcurlを使ってHTTPSにアクセスする方法

phpコード:
$uri = “https://sample.com”;
$ch = curl_init ();
$data=I(‘post.’);
curl_setopt ( $ch, CURLOPT_URL, $uri );
curl_setopt ( $ch, CURLOPT_POST, 1 );
curl_setopt ( $ch, CURLOPT_HEADER, 0 );
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt ( $ch, CURLOPT_POSTFIELDS, $data );
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
$return = curl_exec ( $ch );
dd($return);
curl_close ( $ch );

「PHP入門」Linixの外部コマンドexec(),system(),passthru()を実行する

1.exec()
<?php
exec(“dir”,$output);
print_r($output);
?>

2.system()
<?php
system(“pwd”,$result);
print $result;
?>

3.passthru()
<?php
header(“Content-type:image/gif”);
passthru(“/usr/bin/ppm2tiff /usr/share/tk8.4/demos/images/teapot.ppm”);
?>

4.shell_exec()
<?php
$output = shell_exec(‘ls -lart’);
echo “<pre>$output</pre>”;
?>

5.popen()
<?php
error_reporting(E_ALL);
$handle = popen(‘/path/to/executable 2>&1’, ‘r’);
echo “‘$handle’; ” . gettype($handle) . “\n”;
$read = fread($handle, 2096);
echo $read;
pclose($handle);
?>

CentOS7.0にPHP5.6.30をインストールする

1.phpのダウンロード
# wget http://au1.php.net/get/php-5.6.30.tar.gz/from/this/mirror
#mv mirror php-5.6.30.tar.gz
#tar zxvf php-5.6.30.tar.gz
#cd php-5.6.30
#./configure –prefix=/usr/local/php –with-curl –with-freetype-dir –with-gd –with-gettext –with-iconv-dir –with-kerberos –with-libdir=lib64 –with-libxml-dir –with-MySQL –with-mysqli –with-openssl –with-pcre-regex –with-pdo-mysql –with-pdo-sqlite –with-pear –with-png-dir –with-xmlrpc –with-xsl –with-zlib –enable-fpm –enable-bcmath –enable-libxml –enable-inline-optimization –enable-gd-native-ttf –enable-mbregex –enable-mbstring –enable-opcache –enable-pcntl –enable-shmop –enable-soap –enable-sockets –enable-sysvsem –enable-xml –enable-zip

2.libxml2のインストール
#yum install libxml2
#yum install libxml2-devel -y

3.curlのインストール
#yum install curl curl-devel

4.libpngのインストール
#yum install libpng
#yum install libpng-devel

5.freetypeのインストール
#yum install freetype-devel

#yum install libxslt-devel

6.phpのインストール
#make && make install

7.php.iniのコピー
# cp php.ini-development /usr/local/php/lib/php.ini

#cp -R ./sapi/fpm/php-fpm.conf /usr/local/php/etc/php-fpm.conf
#cp -R ./sapi/fpm/php-fpm /etc/init.d/php-fpm

8.php-fpmを操作
#service php-fpm start
#service php-fpm stop
#service php-fpm restart
#service php-fpm reload

1 / 1012345...10...最後 »