環境変数 LANG が正しく設定されていない可能性あり。
コマンド実行時に設定すればよい。
shell_exec('export LANG=ja_JP.UTF-8; my_command...');
shell_exec('export LANG=ja_JP.UTF-8; my_command...');
$hash = password_hash('raw_password', PASSWORD_DEFAULT);
if(password_verify($raw_password, $hash)) {
echo '認証成功';
} else {
echo '認証失敗';
}
echo '<?xml version="1.0" encoding="utf8"?>';
Theme: テーマ名 Theme URI: テーマのURL Description: テーマの説明 Author: 作者名 Version: テーマのバージョン License: テーマのライセンス License URI: ライセンス本文へのリンク Tags: テーマ検索で参照されるタグ
// if 文の書き方2通り
if(true) {
echo 'yes';
}
if(true) :
echo 'yes';
endif;
// while 文の書き方2通り
$i = 0;
while($i++ < 5) {
echo $i;
}
$i = 0;
while($i++ < 5) :
echo $i;
endwhile;
// for 文の書き方2通り
for($i = 0; $i < 5; $i++) {
echo $i;
}
for($i = 0; $i < 5; $i++) :
echo $i;
endfor;
// foreach 文の書き方2通り
$numbers = array(1, 2, 3, 4, 5);
foreach($numbers as $number) {
echo $i;
}
$numbers = array(1, 2, 3, 4, 5);
foreach($numbers as $number) {
echo $number;
}
// switch 文の書き方2通り
$i = 2;
switch($i) {
case 1:
echo '1';
break;
case 2:
echo '2';
break;
case 3:
echo '3';
break;
}
$i = 2;
switch($i) :
case 1:
echo '1';
break;
case 2:
echo '2';
break;
case 3:
echo '3';
break;
endswitch;
それぞれ { が : へmysql:ホスト名;ポート;DB名;文字コード
function get_names() {
$pdo = new PDO($dsn, $config['dbuser'], $config['dbpass']);
$sth = $pdo->preapre('SELECT `name` FROM `my_table`');
if(!$sth->execute()) {
return false;
}
return $sth->fetchAll(PDO::FETCH_COLUMN);
}
get_names(); // ['tanaka', 'satou', 'suzuki', ...]
$ sudo port install php56-apache2handler
$ cd /opt/local/apache2/modules $ sudo /opt/local/apache2/bin/apxs -a -e -n php5 mod_php56.so
$ sudo apachectl restart
AddType application/x-httpd-php .php
$ sudo port install php56
$ sudo port select php php56
$ php -v
PHP 5.6.2 (cli) (built: Nov 7 2014 02:29:59)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2014 Zend Technologies
with Xdebug v2.2.5, Copyright (c) 2002-2014, by Derick Rethans
mb_send_mail('to@sample.com', 'タイトル', '本文', mb_encode_mimeheader('日本語@sample.com'));
$html = file_get_content('src.html');
$document = new DOMDocument();
@$document->loadHTML($html);
$path = new DOMXPath($document);
// 要素の文字列が"プログラミング"である
$node_list = $path->query('//*[.="プログラミング"]');
// 要素の文字列に"プログラミング"が含まれている
$node_list = $path->query('//*(./text(), "プログラミング")');
// 要素が"target"クラスを持っている、かつ、文字列が"プログラミングである"
$node_list = $path->query('//*[@class="target"][.="プログラミング"]');
$start = 1; // 取得開始番号
$end = 500; // 取得終了番号
$target_url = 'http://target-server.com/page/'; // この後ろに連番が付く
$delay = 10; // アクセス間隔(秒)
for($i = $start; $i <= $end; $i++) {
$html = file_get_contents($target_url . $i);
file_put_contents('dst/' . $i . '.html', $html);
echo "\r" . '(' . $i . '/' . $end . ') を保存完了 残り' . ceil(($end - $i) * $delay / 60) . '分';
sleep($delay);
}
echo "\n" . '全てのページを取得完了';
$ php -a php > $n = (0.1 + 0.7) * 10; php > echo floor($n) . "\n"; 7
php > echo floor(strval($n)) . "\n"; 8
$num = 5;
$sth = $dbh->prepare('SELECT * FROM `my_table` LIMIT :num');
$sth->bindValue(':num', $num);
$sth->execute(); // false
$sth = $dbh->prepare('SELECT * FROM `my_table` LIMIT :num');
$sth->bindValue(':num', $num, PDO::PARAM_INT);
$sth->execute(); // データを取得できる
array (size=3) 0 => string '00000' (length=5) 1 => null 2 => null