Php 构造函数addPage剪切foreach中第一个字母后的所有内容

Php 构造函数addPage剪切foreach中第一个字母后的所有内容,php,arrays,function,foreach,construct,Php,Arrays,Function,Foreach,Construct,我正在开发一个新的UI类,我偶然发现了一个wierd问题,在这个问题上,脚本在第一个字母之后就切断了所有内容。让我给你看看我的代码 class UI { // legger CSS-fil til <head> public function addCSS($css_file) { $this->css[] = array($css_file); } // legger javaScript-fil til <head

我正在开发一个新的UI类,我偶然发现了一个wierd问题,在这个问题上,脚本在第一个字母之后就切断了所有内容。让我给你看看我的代码

class UI {


    // legger CSS-fil til <head>
    public function addCSS($css_file) {
        $this->css[] = array($css_file);
    }

    // legger javaScript-fil til <head>
    public function addJS($js_file) {
        $this->js[] = $js_file;
    }

    // legger sider til <body>
    public function addPage($php_file) {
        $this->php[] = $php_file;
    }

    // Funksjon for add
    public function __construct() {
        // CSS
        $this->addCSS('bootstrap.css');
        $this->addCSS('style.css');

        // JS
        $this->addJS('jquery.js');
        $this->addJS('bootstrap.js');
        $this->addJS('functions.js');

        // Sider
        $this->addPage('home.php');
        $this->addPage('about.php');
    }


    // Struktur for header
    public function getHeader() {
        $html = '<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta keywords="">
    <meta name="author" content="">';

        // Legger inn CSS
        foreach ($this->css as $css) {
            $html .= '
    <link rel="stylesheet" type="text/css" href="css/' . $css[0] . '" />';
        }
    $html .= '
    <title>www.Dan-Levi.no</title>
    <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
      <script src="js/html5shiv.js"></script>
      <script src="js/respond.min.js"></script>
    <![endif]-->
  </head>
  <body>';
  return $html;
    }


    // Struktur for navigasjonen festet til bunn av siden
    public function getNav() {
        $html = '

    <div class="navbar navbar-inverse navbar-fixed-bottom">
        <div class="container">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
            </div>
            <div class="navbar-collapse collapse">
                <ul class="nav navbar-nav">
                    <li class="active"><a href="#">Home</a></li>
                    <li><a href="#about">About</a></li>
                    <li><a href="#contact">Contact</a></li>
                    <li class="dropdown">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown">Other stuff <b class="caret"></b></a>
                    <ul class="dropdown-menu">
                        <li><a href="#">Lorem</a></li>
                        <li><a href="#">Ipsum</a></li>
                        <li><a href="#">Dolor</a></li>
                        <li class="divider"></li>
                        <li class="dropdown-header">Social</li>
                        <li><a href="#">Lorem</a></li>
                        <li><a href="#">Ipsum</a></li>
                        <li><a href="#">Dolor</a></li>
                    </ul>
                    </li>
                </ul>
                <span class="navbar-brand pull-right"><small>&copy; '; $html .= date('Y') ; $html .= ' '. htmlentities('Tømta') .' Data Service</small></span>
            </div><!--/.navbar-collapse -->
        </div>
    </div><!--/.navbar -->';
        return $html;
    }


    // Struktur for siden
    public function getContent() {

        // Legger inn Sider
        foreach ($this->php as $php) {
            include 'pages/'.$php;
        }

    }


    // Struktur for footer
    public function getFooter() {

        // Legger inn javaScript
        foreach ($this->js as $js) {
            $html = '
    <script type="text/javascript" src="js/' . $js[0] . '" ></script>';
        }

        $html .= '

  </body>
</html>';
    return $html;
    }


    // Printer ut sideheader
    public function printHeader() {
        print $this->getHeader();
    }

    // printer ut navigasjonen
    public function printNav() {
        print $this->getNav();
    }

    // printer ut sideinnhold
    public function printContent() {
        print $this->getContent();
    }

    // printer ut sidefooter
    public function printFooter() {
        print $this->getFooter();
    }

}
知道为什么会这样吗?我尝试了一些尝试和错误,读了一些,但我无法理解这一点


非常感谢您的帮助。

我重新编写了代码,现在它可以正常工作了:

// Adds javaScript to <head>
    public function addJavaScript($javascript_file) {
        $this->javascript[] = $javascript_file;
    }

    // Construct
    public function __construct() {
        // JS
        $this->addJavaScript('jquery.js');
        $this->addJavaScript('bootstrap.js');
        $this->addJavaScript('functions.js');

    }

// Adds javaScript (Put this in head)
        foreach ($this->javascript as $js_file) {
            $html .= '
    <script src="js/' . $js_file . '"></script>';
        }
//将javaScript添加到
公共函数addJavaScript($javascript\u文件){
$this->javascript[]=$javascript\u文件;
}
//构造
公共函数构造(){
//JS
$this->addJavaScript('jquery.js');
$this->addJavaScript('bootstrap.js');
$this->addJavaScript('functions.js');
}
//添加javaScript(将其放在头部)
foreach($js_文件形式的此->javascript){
$html.='
';
}
// Adds javaScript to <head>
    public function addJavaScript($javascript_file) {
        $this->javascript[] = $javascript_file;
    }

    // Construct
    public function __construct() {
        // JS
        $this->addJavaScript('jquery.js');
        $this->addJavaScript('bootstrap.js');
        $this->addJavaScript('functions.js');

    }

// Adds javaScript (Put this in head)
        foreach ($this->javascript as $js_file) {
            $html .= '
    <script src="js/' . $js_file . '"></script>';
        }