簡體   English   中英

不需要從PHP重復HTML結果

[英]Unwanted repeating html result from PHP

我不知道這段代碼有什么問題,這是一個錯誤或我在某個地方犯了一個錯誤。 xDebug什么也不顯示。

類腳本

class theme {
    function theme() {
        //show header (meta, style, htmldoctype, script, and title) 
        $this->htmlheader();

        //show main content
        //show footer
    }


    function htmlheader() {
        require "localsettings.php";
        echo "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\n<html>\n<head>\n";
        echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\n";

        echo "<title>$site_name - $page_title</title>\n";
        echo "</head>\n";
    }
}

index.php

require "theme.class.php";
$html = new theme();
//display result
$html->theme();

輸出(錯誤重復)

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>site title - </title>
</head>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>site title - </title>
</head>

當您將函數命名為與類相同時,它就是一個“構造函數”,並在實例化該類時被調用。 因此,您的函數theme()在這里被稱為:

$html = new theme();

和這里:

$html->theme();

刪除后者,您應該會很好。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM