0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

51歳(現52)からのプログラミング 備忘Code

Last updated at Posted at 2020-05-30

var_dump(false==null);
var_dump(false===null);

#ファイル読み書き

access.log
aaa	bbb
aaa	bbb
aaa	bbb
書き込みcode
$ary[]='aaa';
$ary[]='bbb';

$file=fopen('access.log','ab');
flock($file,LOCK_EX);
fwrite($file,implode("\t",$ary)."\n"); //\nは必須と覚える
flock($file,LOCK_UN);
fclose($file);
読み出しcode

<?php
function fopn(){
  $file=fopen('access.log','rb');
  flock($file,LOCK_EX);
  return $file;
}

function fcls($file){
  flock($file,LOCK_UN);
  fclose($file);
}

// --------------------------------------
<?php
function fopn(){
  $file=fopen('access.log','rb');
  flock($file,LOCK_EX);
  return $file;
}

function fcls($file){
  flock($file,LOCK_UN);
  fclose($file);
}

//-----------------------------
function fgcsv(){
  $file=fopn();
  print_r(fgetcsv($file));
  fcls($file);
}

function fg(){
  $file=fopn();
  print_r(fgets($file));
  fcls($file);
}

function f(){
  print_r(file('access.log'));
}

function fgc(){
  print_r(file_get_contents('access.log'));
}

function rf(){
  readfile('access.log');
}

fgcsv();echo '<br>';
fg()   ;echo '<br>';
f()    ;echo '<br>';
fgc()  ;echo '<br>';

// Array ( [0] => aaa bbb )
// aaa bbb
// Array ( [0] => aaa bbb [1] => aaa bbb [2] => aaa bbb )
// aaa bbb aaa bbb aaa bbb
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?