Javaプログラミング初心者のためのページ -28ページ目

PHPの配列は値渡しがデフォルト

PHPでは配列の代入は値渡しがデフォルトです。


<pre>
<?php
$x = array(10, 20, 30);

$y = $x;
$y[1] = 100;
print_r($x);
print_r($y);

$z = &$x;
$z[1] = 200;
print_r($x);
print_r($z);

?>
</pre>

ファイルに行番号をつける

指定したディレクトリ以下にある.phpファイルに行番号をつけて、.php.txtファイルとして保存します。



expandfiles.php

<?php
function to_sjis($input){
$e1 = mb_detect_encoding($input);
$output = mb_convert_encoding($input, "SJIS", $e1);
return $output;
}
function expandfile($filename){
$content = file_get_contents($filename);
$new_content = expand($content, true);
file_put_contents($filename . ".txt", $new_content);
}

function expand($content, $countLineNo = false){
$spaces = array(" ", " ", " ", " ");
$lines = explode("\n", $content);
$w = 0;
if($countLineNo){
if(count($lines) < 10){
$w = 1;
}else if(count($lines) < 100){
$w = 2;
}else{
$w = 3;
}
}

$lineNo = 0;

for($i=0; $i<count($lines); $i++){
$lineNo++;
for($j=0; $j<strlen($lines[$i]); $j++){
$c = substr($lines[$i], $j, 1);
if($c == "\t"){
$lines[$i] = substr_replace($lines[$i], $spaces[$j%4], $j, 1);
}
}
$strLineNo="";
if($countLineNo){
$strLineNo = sprintf("%0".$w."d: ", $lineNo);
}
$lines[$i] = $strLineNo . $lines[$i] . "\n";
}
return $lines;
}

function php_numbering($dirname = "."){
if(!isset($dirname)) $dirname = ".";
$dirname_sjis = to_sjis($dirname);
$files = scandir($dirname_sjis);
foreach($files as $f){
$f = to_sjis($f);
$fullpath = $dirname_sjis . "/" . $f;
if(is_dir($fullpath)
&& !preg_match("/^\.$/", $f)
&& !preg_match("/^\.\.$/", $f)){
php_numbering($fullpath);
}else{
if(preg_match("/\.php$/", $f)){
expandfile($fullpath);
}
}
}
}

if($_GET['dir']){
php_numbering($_GET['dir']);
}
?>
<form>
<input name='dir'>
</form>

あらびき団

これを買うためにamazonのプライム会員になってしまいました。

あらびき団公式パンフレット
¥1,000
Amazon.co.jp

アマゾンサイコー、オモロー。


でも再度見直すと発売は7/30、、、って昨日ですね。

予約してても発売日に発送だから1日遅れになるんだ。

お急ぎ便、って使われないのか?


ちなみに飛脚メール便で届きました。