찾다
php教程PHP源码两个 PHP 类:Table 和 HTMLTable

两个 PHP 类:Table 和 HTMLTable

/*
Code Revised from 

Sam's Teach Yourself Php, Mysql and Apache in 24 Hours 
(Sams Teach Yourself S.) (Paperback)
by Julie C. Meloni 

# Paperback: 616 pages
# Publisher: Sams (1 Jan 2004)
# Language English
# ISBN: 0672326205

*/testing objectsheaders = $headers;
        $this->cols = count ( $headers );
    }

    function addRow( $row ){
        if ( count ($row) != $this->cols )
            return false;
        array_push($this->table_array, $row);
        return true;
    }

    function addRowAssocArray( $row_assoc ) {
        if ( count ($row_assoc) != $this->cols )
            return false;
        $row = array();
        foreach ( $this->headers as $header ) {
            if ( ! isset( $row_assoc[$header] ))
                $row_assoc[$header] = " ";
            $row[] = $row_assoc[$header];
        }
        array_push($this->table_array, $row) ;
    }

    function output() {
         print "";
         foreach ( $this->headers as $header )
             print "$header  ";
         print "\n";
         foreach ( $this->table_array as $y ) {
             foreach ( $y as $xcell )
                 print "$xcell  ";
             print "\n";
         }
         print "";
     }
}

class HTMLTable extends Table{
     var $bgcolor;
     var $cellpadding = "2";
     function HTMLTable( $headers, $bg="#ffffff" ){
         Table::Table($headers);
         $this->bgcolor=$bg;
     }
     function setCellpadding( $padding ){
         $this->cellpadding = $padding;
     }
     function output(){
         print "";
         foreach ( $this->headers as $header )
             print "$header";
         foreach ( $this->table_array as $row=>$cells ) {
             print "";
             foreach ( $cells as $cell )
                 print "$cell";
             print "";
         }
         print "";
     }
}

$test = new HTMLTable( array("a","b","c"), "#00FF00");
$test->setCellpadding( 7 );
$test->addRow( array(1,2,3));
$test->addRow( array(4,5,6));
$test->addRowAssocArray( array ( b=>0, a=>6, c=>3 ));
$test->output();
?>

                   

以上就是的内容,更多相关内容请关注PHP中文网(www.php.cn)!

성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.

핫 AI 도구

Undresser.AI Undress

Undresser.AI Undress

사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover

AI Clothes Remover

사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool

Undress AI Tool

무료로 이미지를 벗다

Clothoff.io

Clothoff.io

AI 옷 제거제

AI Hentai Generator

AI Hentai Generator

AI Hentai를 무료로 생성하십시오.

뜨거운 도구

메모장++7.3.1

메모장++7.3.1

사용하기 쉬운 무료 코드 편집기

SecList

SecList

SecLists는 최고의 보안 테스터의 동반자입니다. 보안 평가 시 자주 사용되는 다양한 유형의 목록을 한 곳에 모아 놓은 것입니다. SecLists는 보안 테스터에게 필요할 수 있는 모든 목록을 편리하게 제공하여 보안 테스트를 더욱 효율적이고 생산적으로 만드는 데 도움이 됩니다. 목록 유형에는 사용자 이름, 비밀번호, URL, 퍼징 페이로드, 민감한 데이터 패턴, 웹 셸 등이 포함됩니다. 테스터는 이 저장소를 새로운 테스트 시스템으로 간단히 가져올 수 있으며 필요한 모든 유형의 목록에 액세스할 수 있습니다.

PhpStorm 맥 버전

PhpStorm 맥 버전

최신(2018.2.1) 전문 PHP 통합 개발 도구

Atom Editor Mac 버전 다운로드

Atom Editor Mac 버전 다운로드

가장 인기 있는 오픈 소스 편집기

ZendStudio 13.5.1 맥

ZendStudio 13.5.1 맥

강력한 PHP 통합 개발 환경