'PHP/functions'에 해당되는 글 3건

  1. 2009/02/23 smarty variable modifier - wordwrap
  2. 2008/09/26 [PHP] 생일로 나이 계산 (2)
  3. 2008/05/07 PHP 디렉토리 함수 (dir)

smarty variable modifier - wordwrap

PHP/functions 2009/02/23 18:06
원문링크:
http://www.smarty.net/manual/en/language.modifier.wordwrap.php

스마티(smarty)의 wordwrap

PHP 의 wordwrap 함수와 같다.
http://www.php.net/manual/en/function.wordwrap.php
예.

<?php

$smarty
->assign('articleTitle'
,
               
"Blind woman gets new kidney from dad she hasn't seen in years."
               
);
?>



{$articleTitle}
{$articleTitle|wordwrap:30}
{$articleTitle|wordwrap:20}
{$articleTitle|wordwrap:30:"<br />\n"}
{$articleTitle|wordwrap:26:"\n":true}

파라미터 설명.
first parameter       : wordwrap 할 컬럼 수 (integer)
second parameter : wordwrap 에 사용되는 문자열
third parameter      :  wordwrap 을 단어 단위로 할지(FALSE) , 엄격하게 캐릭터수로 할지 (TRUE)를 정함.

'PHP > functions' 카테고리의 다른 글

smarty variable modifier - wordwrap  (0) 2009/02/23
[PHP] 생일로 나이 계산  (2) 2008/09/26
PHP 디렉토리 함수 (dir)  (0) 2008/05/07
tags : php, smarty, wordwrap
Trackback 0 : Comment 0

[PHP] 생일로 나이 계산

PHP/functions 2008/09/26 18:10
나이계산때문에....메모

<?php
$birth_time   = strtotime('1995-01-02');
$now          = date('Ymd');
$birthday     = date('Ymd' , $birth_time);
$age           = floor(($now - $birthday) / 10000);
?>

위는 만 나이 계산.

한국 나이로 계산은
<?php
$birth_time   = strtotime('1995-01-02');
$now          = date('Y');
$birthday     = date('Y' , $birth_time);
$age           = $now - $birthday + 1 ;
?>

만 나이 계산때문에 귀찮아서...메모해둠.
 

'PHP > functions' 카테고리의 다른 글

smarty variable modifier - wordwrap  (0) 2009/02/23
[PHP] 생일로 나이 계산  (2) 2008/09/26
PHP 디렉토리 함수 (dir)  (0) 2008/05/07
tags : php
Trackback 0 : Comments 2

PHP 디렉토리 함수 (dir)

PHP/functions 2008/05/07 17:14
  • Directory 클래스의 인스턴스를 생성
  • 생성되는 인스턴스의 클래스 구조는 다음과 같다.

    class Directory {
        string $path ;
        resource $handle ;
        string read ( void )
        void rewind ( void )
        void close ( void )
    }
  • 사용법은 다음과 같음
    1 : <?php
    2 : $d
    = dir("c:\dev\Apache2.2\htdocs"
    );
    3 : echo "<pre>".nl2br(print_r($d,true))."</pre>";

    4 : while (
    false !== ($entry = $d->read
    ())) {
    5 :    echo
    $entry."\n"
    ;
    6 : }
    7 : $d->close
    ();
    8 : ?>


    2번 행의  지정 디렉토리가 오픈됨.
    일단 디렉토리가 오픈되면 2개의 프라퍼티(속성)를 사용할 수 있게 됨.
    3번 행의 출력 결과를 보면

    Directory Object
    (
        [path] => c:\dev\Apache2.2\htdocs
        [handle] => Resource id #2
    )


    handle 속성은 readdir(), rewinddir() , closedir() 같은 다른 디렉토리 함수들과 조합해서 사용가능.
    path 속성은 오픈한 디렉토리패스가 설정됨.
    read, rewind, close  의 3종류의 매소드를 사용할 수 있다.

  • 참고
    php.net  매뉴얼

'PHP > functions' 카테고리의 다른 글

smarty variable modifier - wordwrap  (0) 2009/02/23
[PHP] 생일로 나이 계산  (2) 2008/09/26
PHP 디렉토리 함수 (dir)  (0) 2008/05/07
tags : function, php
Trackback 0 : Comment 0