메뉴 건너뛰기

프로그램언어

조회 수 292 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄

 

 
<h1>function</h1>
<?php
 
//08.31 함수를 통해서 프로그램을 제어한다.
//파일이 있는지 찾는것
//단점: 입력값의 중복이 발생하고 있다. data.txt
var_dump(is_file('data.txt'));
var_dump(is_dir('data.txt'));
var_dump(file_get_contents('data.txt'));
file_put_contents('data.txt',rand(1,100));
 
?>

<h1>object</h1>
 
<?php
//객체 사용
 
//파일의 이름만 바꾸면 밑의 함수들은 동일하게 작동한다.
//연관되어 있는 함수라는 것을 안다.
 
//data.txt를 대상으로 하는 객체
$file = new SplFileObject('data.txt');
 
//객체의 매소드(함수가 클래스에 들어있으면 메소드가 된다.) 호출
var_dump($file->isFile());
var_dump($file->isDir());
var_dump($file->fread($file->getSize()));
$file->fwrite(rand(1,100));

//php 문서에는 이미 SplFileObject라는 class 가 존재한다.
//data2.txt를 대상으로 하는 객체
$file2 = new SplFileObject('data2.txt');
var_dump($file2->isFile());
var_dump($file2->isDir());
var_dump($file2->fread($file2->getSize()));
$file2->fwrite(rand(1 ,100));


 
//SqlFileObject : class - 설계도
// class 에 new를 붙이면 객체를 리턴한다.
// $file, $file2: instance - 설계도를 통해 만들어진 결과물
// isFile, isDir, fread : method(function)
// data.txt , data2.txt : status
 
?>

 

 

<h1>array function style</h1>
 
<?php
 
$adata = array('apple','peach','lemon');

//배열에 원소 추가
array_push($adata,'grape');
 
//반복문
foreach($adata as $item){
 
echo $item.'<br>';
 
}
 
//배열 원소 개수 파악
var_dump(count($adata));
?>

<h1>array object style</h1>
 
<?php
 
//배열 객체 생성
$odata = new ArrayObject(array('apple','peach','lemon'));
 
$odata ->append('grape');
 
// 반복문
foreach($odata as $item){
 
echo $item.'<br>';
}
 
var_dump($odata->count());
 
?>


 


  1. PHP 버전 숨기기 ( php version hide )

    Date2024.02.07 Views79
    Read More
  2. php 두날짜 사이의 모든날짜 배열 만들기

    Date2023.01.12 Views188
    Read More
  3. PHP str_replace php 문자열치환

    Date2023.01.12 Views202
    Read More
  4. PHP 이미지 리사이즈 함수 imagecopyresized

    Date2023.01.12 Views214
    Read More
  5. HTTP 인증하기, 로그인창 띄우기

    Date2021.03.26 Views215
    Read More
  6. [PHP기초] 상속기본

    Date2021.03.27 Views215
    Read More
  7. 코드 생성 하기

    Date2023.01.12 Views216
    Read More
  8. 폴더 용량 체크

    Date2023.01.12 Views225
    Read More
  9. PHP SimpleHtmlDom Parser로 HTML 파싱하기

    Date2023.01.12 Views225
    Read More
  10. 조건문의 함수실행 여부 if ( 0 && ... )

    Date2021.03.26 Views229
    Read More
  11. ereg(), eregi(), ereg_replace(), eregi_replace(), split() 대체

    Date2023.01.12 Views231
    Read More
  12. PHP 파일 업로드 FORM 처리

    Date2023.01.12 Views233
    Read More
  13. 배열 연산자 []= 에 대해서

    Date2021.03.26 Views234
    Read More
  14. 클래스와 인스턴스 그리고 메소드 만들기

    Date2021.03.27 Views235
    Read More
  15. 웹페이지 파싱

    Date2023.01.12 Views236
    Read More
  16. PHP 디렉토리안에 파일 리스트 가져오기

    Date2023.01.12 Views237
    Read More
  17. php www 붙이기

    Date2023.01.12 Views239
    Read More
  18. 상수, 마법상수, 모든 상수 보기

    Date2021.03.26 Views240
    Read More
  19. PHP http -> https 로 전환

    Date2023.01.12 Views240
    Read More
  20. PHP 하위 디렉토리 포함 디렉토리 리스트 출력

    Date2023.01.12 Views240
    Read More
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 17 Next
/ 17

하단 정보를 입력할 수 있습니다

© k2s0o1d4e0s2i1g5n. All Rights Reserved